srkumar Posted December 17, 2007 Share Posted December 17, 2007 Hii,The following is my Xml file:<questions><question id="q1"><head>1.</head> <p>How is Indiana's farming today like its early farming?</p></question><question id="q2"><head>2.</head> <p>How is Indiana's farming today different from its early farming?</p></question></questions><answer idref="q1"><head>1.</head> <p>Many Indian farmers raise corn and hogs today, just as they did in the past.</p></answer><answer idref="q2"><head>2.</head> <p>Today, farmers raise other crops such as soybeans; farms are larger with fewer workers; modern machines have replaced wooden plows and picking corn by hand.</p></answer>I want to convert this as<list type="ol"><li id="q1"><p>How is Indiana's farming today like its early farming?</p></li><li id="q2"><p>How is Indiana's farming today different from its early farming?</p></li></list><list type="ol"><li id="q1"><p>Many Indian farmers raise corn and hogs today, just as they did in the past.</p></li><li id="q2"><p>Today, farmers raise other crops such as soybeans; farms are larger with fewer workers; modern machines have replaced wooden plows and picking corn by hand.</p></li></list>Thanks in Advance,srkumar Link to comment Share on other sites More sharing options...
boen_robot Posted December 17, 2007 Share Posted December 17, 2007 I suppose you also store those elements in some container, as this is not a well formed XML document as it is. Having said that: <xsl:template match="/*"> <xsl:copy> <list type="ol"> <xsl:for-each select="questions/question"> <li id="{@id}"><xsl:copy-of select="p"/></li> </xsl:for-each> </list> <list type="ol"> <xsl:for-each select="answer"> <li id="{@idref}"><xsl:copy-of select="p"/></li> </xsl:for-each> </list> </xsl:copy></xsl:template> Of course there are better ways of doing this, but this probably the easiest one to analyze. Link to comment Share on other sites More sharing options...
srkumar Posted December 18, 2007 Author Share Posted December 18, 2007 Ya.... Its Working Thanks.. Thanks boen.... I suppose you also store those elements in some container, as this is not a well formed XML document as it is. Having said that:<xsl:template match="/*"> <xsl:copy> <list type="ol"> <xsl:for-each select="questions/question"> <li id="{@id}"><xsl:copy-of select="p"/></li> </xsl:for-each> </list> <list type="ol"> <xsl:for-each select="answer"> <li id="{@idref}"><xsl:copy-of select="p"/></li> </xsl:for-each> </list> </xsl:copy></xsl:template> Of course there are better ways of doing this, but this probably the easiest one to analyze. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.