XSL problem
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Tue Dec 21, 2004 4:40 am
XSL problem
Hi, I have xml data as such:
I want to end up being able to export the data to:
Main, a, 1
Main, b, 2
Main, c, 3
Main, d, 3
Any ideas?
Code: Select all
<x:Series>
<x:Data>Main</x:Data>
<x:Category>
<x:Data>{"a","b","c","d","e","f"}</x:Data>
</x:Category>
<x:Value>
<x:Data>{1,2,3,4,5,6}</x:Data>
</x:Value>
</x:Series>
Main, a, 1
Main, b, 2
Main, c, 3
Main, d, 3
Any ideas?
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
First, your document is not wellformed, the prefix x is not bound to a namespace. Assuming as input:
then you can use a named template to output the current line and call it recursivelly for the remainder, something like below:
Output:
Best Regards,
George
First, your document is not wellformed, the prefix x is not bound to a namespace. Assuming as input:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<x:Series xmlns:x="http://test.com">
<x:Data>Main</x:Data>
<x:Category>
<x:Data>{"a","b","c","d","e","f"}</x:Data>
</x:Category>
<x:Value>
<x:Data>{1,2,3,4,5,6}</x:Data>
</x:Value>
</x:Series>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://test.com">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:call-template name="print">
<xsl:with-param name="main" select="x:Series/x:Data"/>
<xsl:with-param name="categories" select="translate(x:Series/x:Category/x:Data, '{ }"', '')"/>
<xsl:with-param name="values" select="translate(x:Series/x:Value/x:Data, '{ }', '')"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="print">
<xsl:param name="main"/>
<xsl:param name="categories"/>
<xsl:param name="values"/>
<xsl:if test="string-length($categories) > 0">
<xsl:choose>
<xsl:when test="contains($categories, ',')">
<xsl:value-of select="$main"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="substring-before($categories, ',')"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="substring-before($values, ',')"/>
<xsl:text xml:space="preserve">
</xsl:text>
<xsl:call-template name="print">
<xsl:with-param name="main" select="$main"/>
<xsl:with-param name="categories" select="substring-after($categories, ',')"/>
<xsl:with-param name="values" select="substring-after($values, ',')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$main"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="$categories"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="$values"/>
<xsl:text xml:space="preserve">
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Code: Select all
Main, a, 1
Main, b, 2
Main, c, 3
Main, d, 4
Main, e, 5
Main, f, 6
George
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