This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Newbie to XSLT
- To: xsl-list at mulberrytech dot com
- Subject: Re: Newbie to XSLT
- From: David Carlisle <davidc at nag dot co dot uk>
- Date: Wed, 9 Feb 2000 14:17:59 GMT
- References: <003c01bf7304$0593d0e0$5461a8c0@tektools.com>
- Reply-To: xsl-list at mulberrytech dot com
>Basically, how do we store the "Cube 47" value in a variable, then use
>it to go back through the document and look for the size for "Cube 47"
>??? )
putting <x> ... </x> around your posted example to make it well formed:
bash-2.01$ xt size.xml size.xsl
<?xml version="1.0" encoding="utf-8"?>
John has size 26 ft.
bash-2.01$
You probably don't need a variable, I used on below to make
the expression a bit easier to read.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="x">
<xsl:for-each select="instance[@name='pc']">
<xsl:value-of select="value"/> has size <xsl:apply-templates select="."/>.
</xsl:for-each>
</xsl:template>
<xsl:template match="instance[@name='pc']">
<xsl:variable name="x" select="../instance[@type='Association']
[reference[@antecedent='pc']/value[.=current()/value]]
/reference[@dependent='location']/value"/>
<xsl:value-of select="../instance[@name='location'][value=$x]/size"/>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list