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

RE: Problem with generating references.

Subject: RE: Problem with generating references.
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Tue, 5 Jul 2005 15:52:04 +0300
RE:  Problem with generating references.
Hi,

> I want to write an XSL file which results in XML file. The
> transformation
> should be like this..
> Note : For the nodes in the above xml file, no attribute is there to
> identify uniquely (No ids are there. But in the result tree,
> I want unique
> id for each element so that I can identify each element uniquely).

Use generate-id(), unless you want the ID to mean something and not just be
unique within that single transformation process.

> 1. Divide the elements into groups.
> 2. While dividing, create the references to the elements in
> the current
> group which are going to be placed in another group.
>
> I want the output XML like this...
> <A-Group>
>          <A1>
>                   <reference id="(id of B1)" />

Say the id of B1 is X

>                   <reference id="(id of B2)" />
>          </A1>
> </A-Group>
> <B-Group>
>          <B1/>

How do you know this is X without marking it up?

	<xsl:key name="group" match="*" use="substring(name(), 1, 1)"/>

	<xsl:template match="/">
		<xsl:for-each select="descendant::*[generate-id() = generate-id(key('group',
substring(name(), 1, 1)))]">
			<xsl:variable name="group" select="substring(name(), 1, 1)"/>
			<xsl:element name="{$group}-Group">
				<xsl:for-each select="key('group', $group)">
					<xsl:copy>
						<xsl:attribute name="id">
							<xsl:value-of select="generate-id()"/>
						</xsl:attribute>
						<xsl:for-each select="*">
							<reference id="{generate-id()}"/>
						</xsl:for-each>
					</xsl:copy>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	</xsl:template>

Cheers,

Jarno

--
In Strict Confidence: Eye Of Heaven

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.