[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

Subject: Re: select all answers belongs to one question from xml with xpath
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Thu, 30 Jun 2005 22:08:29 +0200
xsl for each select all
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>


regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) Ceterum censeo XML omnibus esse utendum

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.