[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XSLT/XPath help to resolve definition references i

Subject: RE: XSLT/XPath help to resolve definition references in a W SDL XML fi le
From: thomas.cherel@xxxxxxxxxxxxxxxxxxxxx
Date: Wed, 4 Sep 2002 15:14:03 -0400
thomas cherel
I thought about that (and this is the way I implemented it today), but I am
not entirely satisfied with this solution as nothing prevents the fact that
a A/@name is a substring of another A/@name attribute. In those cases (may
be rare, but possible), I can get erroneous result.
Thanks for the tip anyway.


-----Original Message-----
From: Stuart Brown [mailto:sbrown@xxxxxxxxxxxxx] 
Sent: Wednesday, September 04, 2002 11:11 AM
To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: RE:  XSLT/XPath help to resolve definition references in a W
SDL XML fi le

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"

 <xsl:variable name="allCs">
   <xsl:text> </xsl:text>
   <xsl:for-each select="/root/C">
     <xsl:value-of select="concat(substring-after(@aRef,':'),' ')"/>

 <xsl:template match="A[contains($allCs,concat(' ',@name,' '))]">
   <xsl:copy-of select="B"/>


This uses string-handling, so there's probably a faster way, particularly if
your file is large.



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


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.
First Name
Last Name
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.