Subject: Re: [xsl] problem using self::node() in for-each From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx> Date: Fri, 21 May 2004 09:55:45 -0700 (PDT) |
Hi Garrett, Please try - <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/root"> <xsl:for-each select="information[@type='info']/instance"> <xsl:variable name="source-id" select="inf_source_id" /> <xsl:value-of select="inf_text" /> - <xsl:value-of select="/root/information[@type='source']/instance[inf_source_id = $source-id]/inf_name" /><xsl:text>
</xsl:text> </xsl:for-each> </xsl:template> </xsl:stylesheet> Regards, Mukul --- Garrett Hynes <garretthynes@xxxxxxxxxxx> wrote: > > I have an XML document with the following structure: > > XML Input > > <root> > <information type="source"> > <instance> > <inf_type>source</type> > <inf_source_id>1</id> > <inf_name>Source 1</name> > </instance> > <instance> > <inf_type>source</type> > <inf_source_id>2</id> > <inf_name>Source 2</name> > </instance> > </information> > <information type="info"> > <instance> > <inf_type>info</type> > <inf_source_id>2</source_id> > <inf_text>Information 1</text> > </instance> > <instance> > <inf_type>info</type> > <inf_source_id>1</source_id> > <inf_text>Information 2</text> > </instance> > <instance> > <inf_type>info</type> > <inf_source_id>1</source_id> > <inf_text>Information 3</text> > </instance> > <instance> > <inf_type>info</type> > <inf_source_id>2</source_id> > <inf_text>Information 4</text> > </instance> > <instance> > <inf_type>info</type> > <inf_source_id>2</source_id> > <inf_text>Information 5</text> > </instance> > <instance> > <inf_type>info</type> > <inf_source_id>1</source_id> > <inf_text>Information 6</text> > </instance> > </information> > </root> > > The inf_source_id in the <information type="info"> > refers to the > inf_source_id in the <information type="source"> > i.e. Information 1 has inf_source_id of 2 meaning it > came from Source 2. > > I'm trying to output all the inf_text using > xsl:for-each along with the name > of the source it has a reference to through > inf_source_id. > > e.g. > > Information 1 - Source 2 > Information 2 - Source 1 > Information 3 - Source 1 > Information 4 - Source 2 > Information 5 - Source 2 > Information 6 - Source 1 > > > However, I can't get the XPath expression to select > the correct source node > using the inf_source_id from the current node to > work. > I've used this method before except not in > <xsl:for-each> and it works fine. > > > XSLT > > <xsl:template name="handleInformation"> > > <xsl:variable name="info" > select="/root/information/instance[inf_type='info']"/> > > <xsl:for-each select="$info"> > > <xsl:variable name="inf_source" > select="/root/information/instance[inf_type = > 'source' and (inf_source_id = > ./inf_source_id)]/inf_name"/> > > <xsl:call-template name="printInformation"> > <xsl:with-param name="source" > select=$inf_source"/> > <xsl:with-param name="text" > select=./inf_text"/> > </xsl:call-template> > > </xsl:for-each> > > </xsl:template> > > Thanks, > > Garrett __________________________________ Do you Yahoo!? Yahoo! Domains Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] problem using self::node(, Jeni Tennison | Thread | [xsl] Grouping, Counting, and Sorti, Thomas F. O'Connell |
Re: [xsl] problem using self::node(, Jeni Tennison | Date | [xsl] Grouping, Counting, and Sorti, Thomas F. O'Connell |
Month |