|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: select all answers belongs to one question from xm
Hi,
Tempore 20:36:25, die 06/30/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit <04083259@xxxxxxxxxxxxx>: i have a set of questions and for each question a set of answers (4 answers )stored in xml file as each each answer has an attribute as a reference to the question that it belogs to as following : You're probably stuck with an xpath because you're missing the 'current()' function. But this situation (nodes connected with references) it is common to use keys. here's a stylesheet demonstrating two methods: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:key name="answer" match="answer" use="@question"/> <xsl:template match="*[ques]"> <h1>My questions</h1> <xsl:apply-templates select="ques"/> </xsl:template> <xsl:template match="question">
<h2><xsl:apply-templates/></h2>
key method:
<ol>
<xsl:for-each select="key('answer',@id)">
<li><xsl:apply-templates/></li>
</xsl:for-each>
</ol>
xpath method:
<ol>
<xsl:for-each select="//answer[@question=current()/@id]">
<li><xsl:apply-templates/></li>
</xsl:for-each>
</ol>
</xsl:template></xsl:stylesheet>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








