first n nodes from a current-group
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 4
- Joined: Wed Jan 23, 2008 2:01 pm
first n nodes from a current-group
Post by manish_jaiswal »
Hi All,
I did a transformation of a XML file.The description is given below-
input XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<School>
<student rec='1'>
<name>Robart J</name>
</student>
<student rec='2'>
<name>Alex M; Peter R; Robart J</name>
</student>
<student rec='3'>
<name>Alex M;Robart J; Dave T</name>
</student>
<student rec='4'>
<name>Alex M;Robart J; Peter R</name>
</student>
</School>
XSLT , I used-
<School>
<xsl:for-each-group select=" School/student group-by="name/tokenize(., ';\s*')">
<xsl:sort data-type="number" select="count(current-group())" order="descending" />
<xsl:sort select="current-grouping-key()"/>
<xsl:for-each select="current-group()" >
<xsl:if test="position()=2">
<name count="{count(current-group())}">
<xsl:value-of select="current-grouping-key()"/>
</name>
</xsl:if>
</xsl:for-each>
</xsl:for-each-group>
</School>
I m getting output like-
<School>
<name count='4'>Robart J</name>
<name count='3'>Alex M</name>
<name count='2'>Peter R</name>
</School>
That is all the name elements having more than or equal to 2 count value.
But I wanted only the first two name elements having highest counts. that is output like:
<School>
<name count='4'>Robart J</name>
<name count='3'>Alex M</name>
</School>
Please help me to do the same.
Thanks in advance.
Manish
I did a transformation of a XML file.The description is given below-
input XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<School>
<student rec='1'>
<name>Robart J</name>
</student>
<student rec='2'>
<name>Alex M; Peter R; Robart J</name>
</student>
<student rec='3'>
<name>Alex M;Robart J; Dave T</name>
</student>
<student rec='4'>
<name>Alex M;Robart J; Peter R</name>
</student>
</School>
XSLT , I used-
<School>
<xsl:for-each-group select=" School/student group-by="name/tokenize(., ';\s*')">
<xsl:sort data-type="number" select="count(current-group())" order="descending" />
<xsl:sort select="current-grouping-key()"/>
<xsl:for-each select="current-group()" >
<xsl:if test="position()=2">
<name count="{count(current-group())}">
<xsl:value-of select="current-grouping-key()"/>
</name>
</xsl:if>
</xsl:for-each>
</xsl:for-each-group>
</School>
I m getting output like-
<School>
<name count='4'>Robart J</name>
<name count='3'>Alex M</name>
<name count='2'>Peter R</name>
</School>
That is all the name elements having more than or equal to 2 count value.
But I wanted only the first two name elements having highest counts. that is output like:
<School>
<name count='4'>Robart J</name>
<name count='3'>Alex M</name>
</School>
Please help me to do the same.
Thanks in advance.
Manish
-
- Posts: 4
- Joined: Wed Jan 23, 2008 2:01 pm
Re: first n nodes from a current-group
Post by manish_jaiswal »
Michael suggested one modification in the code I was trying as below-
<School>
<xsl:for-each-group select=" School/student
group-by="name/tokenize(., ';\s*')">
<xsl:sort data-type="number" select="count(current-group())"
order="descending" />
<xsl:sort select="current-grouping-key()"/>
<xsl:if test="position() <= 2">
<name count="{count(current-group())}">
<xsl:value-of select="current-grouping-key()"/>
</name>
</xsl:if>
</xsl:for-each-group>
</School>
And it is working.
Thanks Michael.
<School>
<xsl:for-each-group select=" School/student
group-by="name/tokenize(., ';\s*')">
<xsl:sort data-type="number" select="count(current-group())"
order="descending" />
<xsl:sort select="current-grouping-key()"/>
<xsl:if test="position() <= 2">
<name count="{count(current-group())}">
<xsl:value-of select="current-grouping-key()"/>
</name>
</xsl:if>
</xsl:for-each-group>
</School>
And it is working.
Thanks Michael.
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