Grouping problem...
Here should go questions about transforming XML with XSLT and FOP.
Grouping problem...
The data I'm working with is coming from an unstructured table source - there is nothing to indicate that a row has ended, other than the sequence of elements.
When the <Price> element is followed by any other element other than itself, (like SKU in this example) I'd like to make thta my indicator of the end of a group.
The input XML is similar to this:
---------------------------------
<onepage>
<prodgroup>
<SKU>No. 447139K5</SKU>
<Price>Price 15.99</Price>
</prodgroup>
<prodgroup>
<SKU>456291K5</SKU>
<SKU>456225K5</SKU>
<SKU>456209K5</SKU>
<Price>159.99</Price>
<Price>169.99</Price>
<SKU>484697K5</SKU>
<SKU>456299K5</SKU>
<SKU>574599K5</SKU>
<Price>169.99</Price>
<Price>169.99</Price>
<SKU>484557K5</SKU>
<SKU>484545K5</SKU>
<SKU>484527K5</SKU>
<Price>169.99</Price>
<Price>289.99</Price>
</prodgroup>
<prodgroup>
<SKU>456237K5</SKU>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>189.99</Price>
<SKU>484552K5</SKU>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>309.99</Price>
</prodgroup>
</onepage>
---------------------------------
The ideal result of XML would be:
---------------------------------
<onepage>
<table>
<row>
<SKU>447139K5</SKU>
<Price>15.99</Price>
</row>
</table>
<table>
<row>
<SKU>456291K5</SKU>
<SKU>456225K5</SKU>
<SKU>456209K5</SKU>
<Price>159.99</Price>
<Price>169.99</Price>
</row>
<row>
<SKU>484697K5</SKU>
<SKU>456299K5</SKU>
<SKU>574599K5</SKU>
<Price>169.99</Price>
<Price>169.99</Price>
</row>
<row>
<SKU>484557K5</SKU>
<SKU>484545K5</SKU>
<SKU>484527K5</SKU>
<Price>169.99</Price>
<Price>289.99</Price>
</row>
</table>
<table>
<row>
<SKU>456237K5</SKU>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>189.99</Price>
</row>
<row>
<SKU>484552K5</SKU>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>309.99</Price>
</row>
</table>
</onepage>
---------------------------------
The XSLT that I've currently written doesn't work properly because I'm using group-ending-with="Price".
Since the Price element can sometimes follow itself,
this creates an unwanted break in my result XML.
Any help would be GREATLY appreciated!
Thanks in advance!
-lmm
When the <Price> element is followed by any other element other than itself, (like SKU in this example) I'd like to make thta my indicator of the end of a group.
The input XML is similar to this:
---------------------------------
<onepage>
<prodgroup>
<SKU>No. 447139K5</SKU>
<Price>Price 15.99</Price>
</prodgroup>
<prodgroup>
<SKU>456291K5</SKU>
<SKU>456225K5</SKU>
<SKU>456209K5</SKU>
<Price>159.99</Price>
<Price>169.99</Price>
<SKU>484697K5</SKU>
<SKU>456299K5</SKU>
<SKU>574599K5</SKU>
<Price>169.99</Price>
<Price>169.99</Price>
<SKU>484557K5</SKU>
<SKU>484545K5</SKU>
<SKU>484527K5</SKU>
<Price>169.99</Price>
<Price>289.99</Price>
</prodgroup>
<prodgroup>
<SKU>456237K5</SKU>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>189.99</Price>
<SKU>484552K5</SKU>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>309.99</Price>
</prodgroup>
</onepage>
---------------------------------
The ideal result of XML would be:
---------------------------------
<onepage>
<table>
<row>
<SKU>447139K5</SKU>
<Price>15.99</Price>
</row>
</table>
<table>
<row>
<SKU>456291K5</SKU>
<SKU>456225K5</SKU>
<SKU>456209K5</SKU>
<Price>159.99</Price>
<Price>169.99</Price>
</row>
<row>
<SKU>484697K5</SKU>
<SKU>456299K5</SKU>
<SKU>574599K5</SKU>
<Price>169.99</Price>
<Price>169.99</Price>
</row>
<row>
<SKU>484557K5</SKU>
<SKU>484545K5</SKU>
<SKU>484527K5</SKU>
<Price>169.99</Price>
<Price>289.99</Price>
</row>
</table>
<table>
<row>
<SKU>456237K5</SKU>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>189.99</Price>
</row>
<row>
<SKU>484552K5</SKU>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>169.99</Price>
<Price>309.99</Price>
</row>
</table>
</onepage>
---------------------------------
The XSLT that I've currently written doesn't work properly because I'm using group-ending-with="Price".
Since the Price element can sometimes follow itself,
this creates an unwanted break in my result XML.
Any help would be GREATLY appreciated!
Thanks in advance!
-lmm
Hi Imm,
You can group the items based on the starting element, that is a SKU that is not preceded by another SKU element, so we take the first preceding sibling element and test not to be a SKU. Full XSL code below:
Best Regards,
George
You can group the items based on the starting element, that is a SKU that is not preceded by another SKU element, so we take the first preceding sibling element and test not to be a SKU. Full XSL code below:
Code: Select all
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="onepage">
<onepage>
<xsl:apply-templates/>
</onepage>
</xsl:template>
<xsl:template match="prodgroup">
<table>
<xsl:for-each-group select="*"
group-starting-with="SKU[not(preceding-sibling::*[1][self::SKU])]">
<row>
<xsl:for-each select="current-group()">
<xsl:copy-of select="."/>
</xsl:for-each>
</row>
</xsl:for-each-group>
</table>
</xsl:template>
</xsl:stylesheet>
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