XSL Multiple sub-items

Here should go questions about transforming XML with XSLT and FOP.
Posts: 1
Joined: Fri Apr 01, 2016 7:51 pm

XSL Multiple sub-items

Post by zesuisse » Fri Apr 01, 2016 7:59 pm


Having the following xml:

Code: Select all

<ns:Layout tableName="AssetRecords">
<ns:Field uid="{af4b2e0c-5f6a-11d2-8f20-0000c0e166dc}" type="0" valueInterpretation="0">
<ns:Field uid="{c02adb31-5c2c-4014-b86a-a53cf83f7e6c}" type="2" valueInterpretation="0">
<ns:Item catalogid="10" id="4">
<ns:FieldValue uid="{af4b2e0c-5f6a-11d2-8f20-0000c0e166dc}">
<ns:FieldValue uid="{c02adb31-5c2c-4014-b86a-a53cf83f7e6c}">4</ns:FieldValue>
I managed to get a text file which looks like:

Code: Select all

But I need to get this (actually one line for each CategoryValue with the corresponding ID)

Code: Select all

The used xslt is as follow:

Code: Select all

  <!-- Parameterized separator/end of line characters for flexibility -->
<xsl:param name="sep" select="'&#09;'" />
<xsl:param name="eol" select="'&#10;'" />
<xsl:param name="listsep" select="'|'" />
<xsl:param name="catsep" select="'&#xa;'" />

<!-- On matching the root node, output a list of field names, followed by the items -->
<xsl:template match="/ns:Export">
<xsl:apply-templates select="ns:Layout/ns:Fields/ns:Field" />
<xsl:apply-templates select="ns:Items/ns:Item"/>

<!-- On matching all but the last field name, output the name followed by separator -->
<xsl:template match="ns:Field[position()!=last()]">
<xsl:value-of select="concat(normalize-space(ns:Name),$sep)" />

<!-- On matching the last field name, output the name followed by a newline -->
<xsl:template match="ns:Field[position()=last()]">
<xsl:value-of select="concat(normalize-space(ns:Name),$eol)" />

<!-- On matching an item, iterate through each field, applying templates to any 'ns:FieldValue' nodes that share the same value of @uid -->
<xsl:template match="ns:Item">
<xsl:variable name="item" select="." />
<xsl:for-each select="/ns:Export/ns:Layout/ns:Fields/ns:Field/@uid">
<xsl:apply-templates select="$item/ns:FieldValue[@uid=current()]" />
<xsl:if test="position()!=last()">
<xsl:value-of select="$sep" />
<xsl:value-of select="$eol" />

<!-- On matching a field value, output the content. -->
<xsl:template match="ns:FieldValue">
<xsl:value-of select="normalize-space(.)" />

<!-- on matching a field value with a @displayValue attribute, output the value of that attribute -->
<xsl:template match="ns:FieldValue[@displayValue]">
<xsl:value-of select="normalize-space(@displayValue)" />

<!-- On matching a field value with ns:CategoryValue children, apply templates on those children. -->
<xsl:template match="ns:FieldValue[ns:CategoryValue]">
<xsl:apply-templates select="ns:CategoryValue" />

<!-- On matching a category value, output it's content, plus a separator. -->
<xsl:template match="ns:CategoryValue">
<xsl:value-of select="concat(normalize-space(.),$listsep)" />
Thanks in advance.