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
Hello,
Having the following xml:
I managed to get a text file which looks like:
But I need to get this (actually one line for each CategoryValue with the corresponding ID)
The used xslt is as follow:
Thanks in advance.
Best,
Alain.
Having the following xml:
Code: Select all
<ns:Layout tableName="AssetRecords">
<ns:Fields>
<ns:Field uid="{af4b2e0c-5f6a-11d2-8f20-0000c0e166dc}" type="0" valueInterpretation="0">
<ns:Name>Categories</ns:Name>
</ns:Field>
<ns:Field uid="{c02adb31-5c2c-4014-b86a-a53cf83f7e6c}" type="2" valueInterpretation="0">
<ns:Name>ID</ns:Name>
</ns:Field>
</ns:Fields>
</ns:Layout>
<ns:Items>
<ns:Item catalogid="10" id="4">
<ns:FieldValue uid="{af4b2e0c-5f6a-11d2-8f20-0000c0e166dc}">
<ns:CategoryValue>$Categories:Cat1</ns:CategoryValue>
<ns:CategoryValue>$Sources:System:Users:alaindefrasne:Desktop</ns:CategoryValue>
</ns:FieldValue>
<ns:FieldValue uid="{c02adb31-5c2c-4014-b86a-a53cf83f7e6c}">4</ns:FieldValue>
</ns:Item>
</ns:Items>
Code: Select all
$Categories:Cat1|$Sources:System:Users:alaindefrasne:Desktop<TAB>4
Code: Select all
$Categories:Cat1<TAB>4
$Sources:System:Users:alaindefrasne:Desktop<TAB>4
Code: Select all
<!-- Parameterized separator/end of line characters for flexibility -->
<xsl:param name="sep" select="'	'" />
<xsl:param name="eol" select="' '" />
<xsl:param name="listsep" select="'|'" />
<xsl:param name="catsep" select="'
'" />
<!-- 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"/>
</xsl:template>
<!-- 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)" />
</xsl:template>
<!-- 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)" />
</xsl:template>
<!-- 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:if>
</xsl:for-each>
<xsl:value-of select="$eol" />
</xsl:template>
<!-- On matching a field value, output the content. -->
<xsl:template match="ns:FieldValue">
<xsl:value-of select="normalize-space(.)" />
</xsl:template>
<!-- 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)" />
</xsl:template>
<!-- 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" />
</xsl:template>
<!-- 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)" />
</xsl:template>
Best,
Alain.
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service