RE: [xsl] Constructing hierarchical XML from a flat XML-tag seque nce using XSLT

Subject: RE: [xsl] Constructing hierarchical XML from a flat XML-tag seque nce using XSLT
From: TSchutzerWeissmann@xxxxxxxxxxxxxxxx
Date: Tue, 27 Aug 2002 11:55:55 +0100
Hi Lars,

	The easiest thing here is to use a key.

<xsl:key name="childrenNotSiblings" match="b|c|d"
use="generate-id(preceding-sibling::a[1])"/>

<xsl:template match="a">
  <a>
	<xsl:for-each select="key('childrenNotSiblings',generate-id())">
      		<xsl:copy-of select="."/>
	</xsl:for-each>
  </a>
</xsl:template>

If I've understood right you want to put all the non-a nodes that follow an
empty a node
inside it. Using a key will bundle all those nodes up and you can fetch them
using a reference
to the a node.

cheers,
Tom
> -----Original Message-----
> From: Lars Eskildsen [mailto:laes@xxxxxxxxx]
> Sent: 27 August 2002 11:35
> To: XSLT List (E-mail)
> Subject: [xsl] Constructing hierarchical XML from a flat XML-tag
> sequence using XSLT
> 
> 
> Hello!
> 
> I want to be able to convert XML code like
> 
> <XMLCODE>
> <a/><b/><c/><d/> <a/><b/><c/><d/> <a/><b/><c/><d/> <a/><b/><c/><d/>
> </XMLCODE>
> 
> to the following XML:
> 
> <NEWXMLCODE>
> <a>
> 	<b/>
> 	<c/>
> 	<d/>
> </a>
> <a>
> 	<b/>
> 	<c/>
> 	<d/>
> </a>
> <a>
> 	<b/>
> 	<c/>
> 	<d/>
> </a>
> </NEWXMLCODE>
> 
> The DTD for the input XML is:	<!ELEMENT XMLCODE (a | b | c | d)+>
> 				a, b, c, d are empty tags
> 
> The DTD for the output XML is:	<!ELEMENT NEWXMLCODE (a+)>
>                                                 <!ELEMENT a 
> (b | c | d)*>
> 				b, c, d are empty tags
> 
> Can this be done? and how? 
> I just can't figure it out!
> 
> /Lars Eskildsen
</xsl:template>

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


Current Thread