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

Re: Replacing a string by another which is found by referenc

Subject: Re: Replacing a string by another which is found by reference in the same XML document
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 16 Jun 2000 21:28:34 +0100
replacing uuid
Hi Vincent,

>My source XML contains something like:
> <Root>
> <Class
>      Name="MyClass"
>      Uuid="80A2B3BD-0000-520C-383BE4980006BE67"
>      TargetRef="80A2B3BD-0000-520C-383BE4980006A75A">
></Class>
>
><AnotherObject
>Name="MyObject"
>Uuid="80A2B3BD-0000-520C-383BE4980006B687">
></AnotherObject>
></Root>
>
>I have an XSL style sheet  to display it on IE5 with apropriate style. I
>would like to get as output:
>
>Class:
>Name="MyClass"
>TargetRef="MyObject"
>
>Where the TargetRef string has been replaced by the value of the string
>with the same Uuid.

This seems to me to be a good instance to use xsl:key to identify the nodes that are uniquely identified through the 'Uuid' attribute.  First, set up the key:
* name  - a name for the key, anything you like
* match - an XPath matching the nodes that you want to identify
* use   - an XPath (relative to the 'match' node) that identifies the node

In your case:

<xsl:key name="objects" match="*[@Uuid]" use="@Uuid" />

Note that I haven't named the (element) nodes that are identified by the key because it isn't clear to me whether your 'Class' and 'AnotherObject' elements are indicative of a whole range of possible element names in your input, but we can guarantee at least that they will have a 'Uuid' attribute if they're worth identifying!

Then you can access a particular node through its 'Uuid' attribute using the key() function, so try:

<xsl:template match ="Class">
  Class:
  Name="<xsl:value-of select="@Name" />"
  TargetRef="<xsl:value-of select="key('objects', @TargetRef)/@Name" />"
</xsl:template>

This works in SAXON.  I'm not sure about you using IE5: it depends on what version of MSXML you have - the old one at least didn't support keys.

I hope that helps,

Jeni

Jeni Tennison
http://friday.u-net.com/jeni/


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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