How to "flatten" an input document?

Subject: How to "flatten" an input document?
From: Gordon Vidaver <gvidaver@xxxxxxx>
Date: Tue, 13 Jun 2000 22:17:43 -0400
Hi,
I'm new to XSL so perhaps this is an easy problem for someone more experienced.


I have an input document that's a set of nested tags :

	<X>
	  <Y>
	    <Z/>
	  </Y>
	</X>

And I want to generate an output document that looks like this:

	<X>
	  <ref type="Y">
	</X>
	<Y>
	  <ref type="Z">
	</Y>
	<Z/>

Essentially "flattening" the original document. Instead of nested tags, there should be just references to other tags that are children of the root.

This does not seem to be possible in XSL, since there doesn't seem to be any way to output two elements at different places in the output tree as a result of one rule. Modes seem to let you have multiple matching rules, but they can only produce sibling elements in the output.

There's also seemingly no way to put an element at an arbitrary place in the output tree. For instance, if I could somehow have a command that put elements at the root of the output tree, I could do something like this:

<xsl:template match="*">
<xsl:for-each select="*">
ref
<xsl:attribute name="type">
<xsl:value-of select=".">
</xsl:attribute>

<xsl:put-element-at select-in-output="/"> <-- this is my imagined command -->
<xsl:copy-of select=".">
</xsl:put-element-at>

<xsl:apply-templates/>
</xsl:template>


Is this type of thing possible in XSL? Is there something I'm missing? Or do I need to use an XSL extension?

Any help anyone can provide would be most appreciated.

Thanks,

Gordon


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



Current Thread