Subject: Re: [xsl] Howto follow embedded Xpaths in XSL From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx> Date: Thu, 12 Aug 2010 15:15:39 +0200 |
$ xsltproc comprefs.xsl data.xml 'Component 1'<magicNumber value="27"/> 'Component 2'<magicNumber value="42"/> $ cat comprefs.xsl <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dyn="http://exslt.org/dynamic" > <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:template match="/"> <xsl:variable name="root" select="."/> <xsl:for-each select="//component"> <xsl:value-of select="@displayName"/> <xsl:variable name="ref" select="string(*/@reference)"/> <xsl:for-each select="$root"> <xsl:copy-of select="dyn:evaluate($ref)/magicNumber"/> </xsl:for-each> <xsl:text> </xsl:text> </xsl:for-each> </xsl:template> </xsl:stylesheet> $ $ cat data.xml <root> <component displayName="'Component 1'"> <stream displayName="Elementary Stream" reference="/root [1]/anotherElement[1]"> <node value="bob"/> </stream> </component> <anotherElement> <magicNumber value="27"/> </anotherElement> <component displayName="'Component 2'"> <stream displayName="Elementary Stream" reference="/root [1]/anotherElement[2]"> <node value="bob"/> </stream> </component> <anotherElement> <magicNumber value="42"/> </anotherElement> </root> $ Mit besten Gruessen / Best wishes, Hermann Stamm-Wilbrandt Developer, XML Compiler, L3 WebSphere DataPower SOA Appliances ---------------------------------------------------------------------- IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschaeftsfuehrung: Dirk Wittkopp Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294 From: Daniel Laird <danieljlaird@xxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Date: 08/12/2010 12:21 PM Subject: [xsl] Howto follow embedded Xpaths in XSL Hi I am new to XSL and relatively new to XML as well. I have some XML that as an attribute has a value that is an xpath to another location within the same document - however it is not a child etc. Is there any way for XSL to get the value of this node and then get the value of nodes at this location? <root> <component displayName="Component 1"> <stream displayName="Elementary Stream" reference="/root [1]/anotherElement[1]"> <node value="bob"> </stream> </component> <anotherElement> <magicNumber value="27"/> </anotherElement> </root> So in the above example, I want to do an XSL function that 1. finds all components 2. For each component get the value of <magicNumber> that is linked from the reference attribute of my component node. In this example it does not look very helpful but my real data is massive and this would stop lots of repeated nodes and data etc (effectively symlinks within the document) Hope this is clear and you can help Dan
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Howto follow embedded Xpa, Michael Kay | Thread | Re: [xsl] Howto follow embedded Xpa, Daniel Laird |
Re: [xsl] Re: Problem with grouping, Martin Honnen | Date | [xsl] Test syntax, compare a string, Peter Desjardins |
Month |