Subject: RE: [xsl] XSLT/XPath help to resolve definition references in a W SDL XML fi le From: Stuart Brown <sbrown@xxxxxxxxxxxxx> Date: Wed, 4 Sep 2002 16:11:20 +0100 |
Hi Thomas, > Let's say that I have an XML document looking like that: > > <root> > <A name="a1"><B .../></A> > <A name="a2"><B .../></A> > <A name="a3"><B .../></A> > <C aRef="ns1:a1"/> > <C aRef="ns2:a2"/> > </root> > > I want to be able to select all the B element which are under > the A elements > referenced by the C element (the A elements for which a > C/@aRef attribute > value, minus the prefix, is equal to the A/@name attribute). I'd bundle up all the @aRef attributes space separated into a global variable, and then use a predicate to only select those A elements whose name attribute is contained in the variable string. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:variable name="allCs"> <xsl:text> </xsl:text> <xsl:for-each select="/root/C"> <xsl:value-of select="concat(substring-after(@aRef,':'),' ')"/> </xsl:for-each> </xsl:variable> <xsl:template match="A[contains($allCs,concat(' ',@name,' '))]"> <xsl:copy-of select="B"/> </xsl:template> </xsl:stylesheet> This uses string-handling, so there's probably a faster way, particularly if your file is large. Cheers, Stuart XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSLT/XPath help to resolv, TSchutzerWeissmann | Thread | RE: [xsl] XSLT/XPath help to resolv, thomas . cherel |
Re: [xsl] XSLT/XPath help to resolv, David Carlisle | Date | Re: [xsl] sort problem, David Carlisle |
Month |