[xsl] splitting multiple occurrences of an element within another element

Subject: [xsl] splitting multiple occurrences of an element within another element
From: "Brian Benson" <bbenson@xxxxxxxxxxxx>
Date: Wed, 24 Sep 2003 12:39:43 -0500
I am very new to xsl and really struggling to get the results that I want.

I am trying to convert an xml file that looks like this
====================
<database>
     <document form='formname'>
          <noteinfo unid='abc'/>
          <doclink document='1'/>
          <doclink document='2'/>
     </document>
</database>

Into an xml file that looks like this
=====================
</database>
     <document>
          <form>formname</form>
          <unid>abc</unid>
          <doclink>1</doclink>
     </document>

     <document>
          <form>formname</form>
          <unid>abc</unid>
          <doclink>2</doclink>
     </document>
</database>


The xslt that I have so far works well, except for the following:
1) If there is more than one doclink in one document, they need to be split
into multiple documents so that there is one doclink per document.  The xsl
below puts all doclinks in one document.
2) The form and unid attributes are output as attributes and they need to
be converted to elements.

I have been able to get both of the above to work, but not at the same
time.  Any help is appreciated.

The xslt that I have so far looks like this:
=====================
<xsl:template match="/">
     <database>
          <xsl:apply-templates/>
     </database>
</xsl:template>

<xsl:template match="dxl:document">
     <document>
          <xsl:copy-of select="@form | dxl:noteinfo/@unid
|.//dxl:doclink"/>
     </document>

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


<!-- remove all other text and attributes -->
<xsl:template match ="text()|@*"></xsl:template>

<!-- remove all documents with no doc links -->
<xsl:template match ="dxl:document[not(.//dxl:doclink)]"></xsl:template>





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


Current Thread