xsl:for-each-group positional grouping [duplicate] - xpath

This question already has an answer here:
xsl:for-each-group positional grouping flat xml to hierarchical
(1 answer)
Closed 8 years ago.
I have a flat xml file that needs to be converted to hierarchical. I used the nested grouping idea from here xsl:for-each-group help needed. It's working for the most part except for a couple of issues:
1) The elements root1 and root2 are not showing up.
2) The location of element level21 is incorrect. The first level21 with sequencecount=2 should be between the 2 level2 elements.
Any help is really appreciated.
Thanks.
Source XML
<root>
<root1>1234</root1>
<root2>5678</root2>
<level1>
<a>line 1</a>
<b>line 2</b>
<c>line 3</c>
</level1>
<level2>
<d>line 4</d>
<e>line 5</e>
<f>line 6</f>
<g>line 7</g>
</level2>
<level3>
<h>line 8</h>
<i>line 9</i>
<j>line 10</j>
<k>line 11</k>
<l>line 12</l>
</level3>
<level4>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
<level4>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
<level21>
<d>line 214</d>
<e>line 215</e>
<f>line 216</f>
<g>line 217</g>
</level21>
<level2>
<d>line 19</d>
<e>line 20</e>
<f>line 21</f>
<g>line 22</g>
</level2>
<level3>
<h>line 23</h>
<i>line 24</i>
<j>line 25</j>
<k>line 26</k>
<l>line 27</l>
</level3>
<level4>
<m>line 28</m>
<n>line 29</n>
<o>line 30</o>
</level4>
<level4>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
<level21>
<d>line 224</d>
<e>line 225</e>
<f>line 226</f>
<g>line 227</g>
</level21>
Required Result XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<root1>1234</root1>
<root2>5678</root2>
<level1>
<a>line 1</a>
<b>line 2</b>
<c>line 3</c>
<level2>
<d>line 4</d>
<e>line 5</e>
<f>line 6</f>
<g>line 7</g>
<level3>
<SequenceCount>1</SequenceCount>
<h>line 8</h>
<i>line 9</i>
<j>line 10</j>
<k>line 11</k>
<l>line 12</l>
<level4>
<SequenceCount>1</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
<level4>
<SequenceCount>2</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
</level3>
</level2>
<level21>
<SequenceCount>2</SequenceCount>
<d>line 214</d>
<e>line 215</e>
<f>line 216</f>
<g>line 217</g>
</level21>
<level2>
<d>line 19</d>
<e>line 20</e>
<f>line 21</f>
<g>line 22</g>
<level3>
<SequenceCount>3</SequenceCount>
<h>line 23</h>
<i>line 24</i>
<j>line 25</j>
<k>line 26</k>
<l>line 27</l>
<level4>
<SequenceCount>1</SequenceCount>
<m>line 28</m>
<n>line 29</n>
<o>line 30</o>
</level4>
<level4>
<SequenceCount>2</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
</level3>
</level2>
<level21>
<SequenceCount>4</SequenceCount>
<d>line 224</d>
<e>line 225</e>
<f>line 226</f>
<g>line 227</g>
</level21>
</level1>
</root>
My XSL
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="fn" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"
exclude-result-prefixes="xs fn">
<xsl:output indent="yes" />
<xsl:template match="/">
<xsl:for-each-group select="*" group-starting-with="root">
<root>
<xsl:for-each-group select="*" group-starting-with="*[name(.)='level1']">
<xsl:choose>
<xsl:when test="name(.)='level1'">
<level1>
<xsl:apply-templates />
<xsl:for-each-group select="current-group()" group-starting-with="*[name(.)='level2']">
<xsl:choose>
<xsl:when test="name(.)='level2'">
<level2>
<xsl:apply-templates />
<xsl:for-each-group select="current-group()" group-starting-with="*[name(.)='level3']">
<xsl:choose>
<xsl:when test="name(.)='level3'">
<level3>
<xsl:element name="SequenceCount"><xsl:number count="level3|level21" level="any"/></xsl:element>
<xsl:apply-templates />
<xsl:for-each-group select="current-group()" group-starting-with="*[name(.)='level4']">
<xsl:choose>
<xsl:when test="name(.)='level4'">
<level4>
<xsl:element name="SequenceCount"><xsl:number value="position() - 1"/></xsl:element>
<xsl:apply-templates />
</level4>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</level3>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</level2>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
<xsl:for-each-group select="current-group()" group-starting-with="*[name(.)='level21']">
<xsl:choose>
<xsl:when test="name(.)='level21'">
<level21>
<xsl:element name="SequenceCount"><xsl:number count="level3|level21" level="any"/></xsl:element>
<xsl:apply-templates />
</level21>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</level1>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</root>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Current Output XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<level1>
<a>line 1</a>
<b>line 2</b>
<c>line 3</c>
<level2>
<d>line 4</d>
<e>line 5</e>
<f>line 6</f>
<g>line 7</g>
<level3>
<SequenceCount>1</SequenceCount>
<h>line 8</h>
<i>line 9</i>
<j>line 10</j>
<k>line 11</k>
<l>line 12</l>
<level4>
<SequenceCount>1</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
<level4>
<SequenceCount>2</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
</level3>
</level2>
<level2>
<d>line 19</d>
<e>line 20</e>
<f>line 21</f>
<g>line 22</g>
<level3>
<SequenceCount>3</SequenceCount>
<h>line 23</h>
<i>line 24</i>
<j>line 25</j>
<k>line 26</k>
<l>line 27</l>
<level4>
<SequenceCount>1</SequenceCount>
<m>line 28</m>
<n>line 29</n>
<o>line 30</o>
</level4>
<level4>
<SequenceCount>2</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
</level3>
</level2>
<level21>
<SequenceCount>2</SequenceCount>
<d>line 214</d>
<e>line 215</e>
<f>line 216</f>
<g>line 217</g>
</level21>
<level21>
<SequenceCount>4</SequenceCount>
<d>line 224</d>
<e>line 225</e>
<f>line 226</f>
<g>line 227</g>
</level21>
</level1>
</root>

I think the following stylesheet gives you the grouping you want:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="xs mf">
<xsl:output indent="yes"/>
<xsl:function name="mf:group" as="node()*">
<xsl:param name="elements" as="element()*"/>
<xsl:param name="level" as="xs:integer"/>
<xsl:for-each-group select="$elements" group-starting-with="*[starts-with(local-name(), concat('level', $level))]">
<xsl:choose>
<xsl:when test="self::*[starts-with(local-name(), concat('level', $level))]">
<xsl:copy>
<xsl:if test="$level = (3, 4)">
<SequenceCount><xsl:value-of select="position()"/></SequenceCount>
</xsl:if>
<xsl:apply-templates/>
<xsl:sequence select="mf:group(current-group() except ., $level + 1)"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:function>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* , node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root">
<xsl:copy>
<xsl:sequence select="mf:group(*, 1)"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
For the SequenceCount element some values are as in your posted result sample, some are different, some are missing. Let's first establish whether the grouping is as you want it, then we can try to improve the sequence count value. You might want to explain in writing what that count refers to.
[edit]Based on your XSLT code I have added code to compute the SequenceNumber for the different levels, the complete stylesheet is now
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="xs mf">
<xsl:output indent="yes"/>
<xsl:function name="mf:group" as="node()*">
<xsl:param name="elements" as="element()*"/>
<xsl:param name="level" as="xs:integer"/>
<xsl:for-each-group select="$elements" group-starting-with="*[starts-with(local-name(), concat('level', $level))]">
<xsl:choose>
<xsl:when test="self::*[starts-with(local-name(), concat('level', $level))]">
<xsl:copy>
<xsl:choose>
<xsl:when test="self::level3">
<SequenceCount><xsl:number count="level3 | level21"/></SequenceCount>
</xsl:when>
<xsl:when test="self::level4">
<SequenceCount><xsl:value-of select="position()"/></SequenceCount>
</xsl:when>
<xsl:when test="self::level21">
<SequenceCount><xsl:number count="level3|level21"/></SequenceCount>
</xsl:when>
</xsl:choose>
<xsl:apply-templates/>
<xsl:sequence select="mf:group(current-group() except ., $level + 1)"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:function>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* , node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root">
<xsl:copy>
<xsl:sequence select="mf:group(*, 1)"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
With Saxon for the input
<root>
<root1>1234</root1>
<root2>5678</root2>
<level1>
<a>line 1</a>
<b>line 2</b>
<c>line 3</c>
</level1>
<level2>
<d>line 4</d>
<e>line 5</e>
<f>line 6</f>
<g>line 7</g>
</level2>
<level3>
<h>line 8</h>
<i>line 9</i>
<j>line 10</j>
<k>line 11</k>
<l>line 12</l>
</level3>
<level4>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
<level4>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
<level21>
<d>line 214</d>
<e>line 215</e>
<f>line 216</f>
<g>line 217</g>
</level21>
<level2>
<d>line 19</d>
<e>line 20</e>
<f>line 21</f>
<g>line 22</g>
</level2>
<level3>
<h>line 23</h>
<i>line 24</i>
<j>line 25</j>
<k>line 26</k>
<l>line 27</l>
</level3>
<level4>
<m>line 28</m>
<n>line 29</n>
<o>line 30</o>
</level4>
<level4>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
<level21>
<d>line 224</d>
<e>line 225</e>
<f>line 226</f>
<g>line 227</g>
</level21>
</root>
I get the result
<root>
<root1>1234</root1>
<root2>5678</root2>
<level1>
<a>line 1</a>
<b>line 2</b>
<c>line 3</c>
<level2>
<d>line 4</d>
<e>line 5</e>
<f>line 6</f>
<g>line 7</g>
<level3>
<SequenceCount>1</SequenceCount>
<h>line 8</h>
<i>line 9</i>
<j>line 10</j>
<k>line 11</k>
<l>line 12</l>
<level4>
<SequenceCount>1</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
<level4>
<SequenceCount>2</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
</level3>
</level2>
<level21>
<SequenceCount>2</SequenceCount>
<d>line 214</d>
<e>line 215</e>
<f>line 216</f>
<g>line 217</g>
</level21>
<level2>
<d>line 19</d>
<e>line 20</e>
<f>line 21</f>
<g>line 22</g>
<level3>
<SequenceCount>3</SequenceCount>
<h>line 23</h>
<i>line 24</i>
<j>line 25</j>
<k>line 26</k>
<l>line 27</l>
<level4>
<SequenceCount>1</SequenceCount>
<m>line 28</m>
<n>line 29</n>
<o>line 30</o>
</level4>
<level4>
<SequenceCount>2</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</level4>
</level3>
</level2>
<level21>
<SequenceCount>4</SequenceCount>
<d>line 224</d>
<e>line 225</e>
<f>line 226</f>
<g>line 227</g>
</level21>
</level1>
</root>

Related

Apache FOP image not hide

I set margin-right:1.0in.
The last column show the image but hide the text. I know the last column is overflow, but why the the image is showing but the text not?
How to hide all of the content include the image?
The file content is like below:
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master page-height="8.5in" page-width="14.0in" margin-left="0.1in" margin-right="1.0in" margin-bottom="0.2in" margin-top="0.2in" master-name="all-pages">
<fo:region-body region-name="xsl-region-body" margin-bottom="0.1in" margin-top="0.1in"/>
<fo:region-before extent="0.1in" region-name="xsl-region-header"/>
<fo:region-after extent="0.1in" region-name="xsl-region-footer"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="reportSeqn1PageMasterParametersSet">
<fo:repeatable-page-master-reference master-reference="all-pages"/>
</fo:page-sequence-master>
<fo:page-sequence-master master-name="reportSeqn1PageMasterColumnSet1">
<fo:repeatable-page-master-reference master-reference="all-pages"/>
</fo:page-sequence-master>
<fo:page-sequence-master master-name="reportSeqn1PageMasterColumnSet2">
<fo:repeatable-page-master-reference master-reference="all-pages"/>
</fo:page-sequence-master>
<fo:page-sequence-master master-name="reportSeqn1PageMasterImageSet">
<fo:repeatable-page-master-reference master-reference="all-pages"/>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence force-page-count="no-force" master-reference="reportSeqn1PageMasterColumnSet1" initial-page-number="1">
<fo:static-content flow-name="xsl-region-header">
<fo:block font-family="Arial" font-size="8pt" text-align="end">Dec 07, 2016</fo:block>
<fo:block font-family="Arial" font-size="8pt" text-align="end">05:55 PM</fo:block>
<fo:block font-weight="normal" font-family="Arial" font-size="12pt" text-align="center" text-decoration="none">Finance Integration Tasks</fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-footer">
<fo:block font-family="Arial" font-size="8pt" text-align="end">
Page <fo:page-number/> Column set 1 of 2</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block-container width="1653.2640000000001pt">
<fo:block font-family="Arial" font-size="8pt" margin-top="5pt">
<fo:table table-layout="fixed" width="1653.2640000000001pt">
<fo:table-column column-number="1" column-width="84.43636363636364pt"/>
<fo:table-column column-number="2" column-width="84.43636363636364pt"/>
<fo:table-column column-number="3" column-width="84.43636363636364pt"/>
<fo:table-column column-number="4" column-width="84.43636363636364pt"/>
<fo:table-column column-number="5" column-width="84.43636363636364pt"/>
<fo:table-column column-number="6" column-width="84.43636363636364pt"/>
<fo:table-column column-number="7" column-width="84.43636363636364pt"/>
<fo:table-column column-number="8" column-width="84.43636363636364pt"/>
<fo:table-column column-number="9" column-width="84.43636363636364pt"/>
<fo:table-column column-number="10" column-width="84.43636363636364pt"/>
<fo:table-column column-number="11" column-width="84.43636363636364pt"/>
<fo:table-column column-number="12" column-width="724.464pt"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(51,102,153)">
<fo:block text-align="start" color="rgb(255,255,255)"># of Critical Issues</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(51,102,153)">
<fo:block text-align="start" color="rgb(255,255,255)">Description</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(51,102,153)">
<fo:block text-align="start" color="rgb(255,255,255)"># of Other Issues</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(51,102,153)">
<fo:block text-align="start" color="rgb(255,255,255)">Test</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(51,102,153)">
<fo:block text-align="start" color="rgb(255,255,255)">Test1</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(51,102,153)">
<fo:block text-align="start" color="rgb(255,255,255)">Test2</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(51,102,153)">
<fo:block text-align="start" color="rgb(255,255,255)">Test3</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(51,102,153)">
<fo:block text-align="start" color="rgb(255,255,255)">Test4</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(51,102,153)">
<fo:block text-align="start" color="rgb(255,255,255)">Test5</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(51,102,153)">
<fo:block text-align="start" color="rgb(255,255,255)">Test6</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(51,102,153)">
<fo:block text-align="start" color="rgb(255,255,255)">Test7</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(255,255,255)" border-top-color="rgb(255,255,255)" border-right-color="rgb(255,255,255)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(255,255,255)">
<fo:block text-align="start" color="rgb(255,255,255)">title</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="#ffff00">
<fo:block-container >
<fo:block font-family="Arial" color="Black" text-align="left">
<fo:inline xmlns:exslt="http://exslt.org/common" color="Black" font-weight="normal" font-style="normal" text-decoration="none">Tin
Can</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(255,255,255)">
<fo:block-container >
<fo:block font-family="Arial" color="Red" text-align="left" font-weight="bold">
<fo:inline xmlns:exslt="http://exslt.org/common" color="Red" font-weight="bold" font-style="normal" text-decoration="none">ABCD</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(255,255,255)">
<fo:block-container >
<fo:block font-family="Arial" color="Black" text-align="center">
<fo:inline xmlns:exslt="http://exslt.org/common" color="Black" font-weight="normal" font-style="normal" text-decoration="none">4</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(255,255,255)">
<fo:block-container >
<fo:block font-family="Arial" color="Black" text-align="right">
<fo:inline xmlns:exslt="http://exslt.org/common" color="Black" font-weight="normal" font-style="normal" text-decoration="none">19</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(255,255,255)">
<fo:block-container >
<fo:block font-family="Arial" color="Black" text-align="left">
<fo:inline xmlns:exslt="http://exslt.org/common" color="Black" font-weight="normal" font-style="normal" text-decoration="none">Tin
Can</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(255,255,255)">
<fo:block-container >
<fo:block font-family="Arial" color="#000000" text-align="left">ABCD</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(255,255,255)">
<fo:block-container >
<fo:block font-family="Arial" color="#000000" text-align="left">Tin Can</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(255,255,255)">
<fo:block-container >
<fo:block font-family="Arial" color="#000000" text-align="left">ABCD</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(255,255,255)">
<fo:block-container >
<fo:block font-family="Arial" color="#000000" text-align="left">Tin Can</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(255,255,255)">
<fo:block-container >
<fo:block font-family="Arial" color="#000000" text-align="left">ABCD</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(200,215,227)" border-top-color="rgb(200,215,227)" border-right-color="rgb(200,215,227)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(255,255,255)">
<fo:block-container >
<fo:block font-family="Arial" color="Black" text-align="right">
<fo:inline xmlns:exslt="http://exslt.org/common" color="Black" font-weight="normal" font-style="normal" text-decoration="none">Tin
Can</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding="2pt" border-bottom-color="rgb(255,255,255)" border-top-color="rgb(255,255,255)" border-right-color="rgb(255,255,255)" border-left-color="rgb(200,215,227)" border-style="solid" border-width="0.25pt" background-color="rgb(255,255,255)">
<fo:block-container >
<fo:block font-family="Arial" color="rgb(255,255,255)" text-align="left">
<fo:inline xmlns:exslt="http://exslt.org/common" font-weight="normal" font-style="normal">ABCD</fo:inline> <fo:external-graphic src="url('file:///C:/Users/sujianrong/Desktop/fop-2.1-bin.tar/fop-2.1-bin/fop-2.1/examples/fo/graphics/fop.jpg')" content-width="10pt" /> </fo:block>
</fo:block-container>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
</fo:block-container>
<fo:block id="reportSeqn1last-pageColumnSet2"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
Add overflow="hidden" to the fo:region-body.
See https://www.w3.org/TR/xsl11/#overflow

xslt sorting for some part of a file

I'm very new to XSLT, and I want to sort a part of XML file.(keeping all the file data)
Here's the file :
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd">
<SchemaVersion>1.0</SchemaVersion>
<Header>### uVision Project, (C) Keil Software</Header>
<Extensions>
<cExt>*.c</cExt>
<aExt>*.s*; *.src; *.a*</aExt>
<oExt>*.obj</oExt>
<lExt>*.lib</lExt>
<tExt>*.txt; *.h; *.inc</tExt>
<pExt>*.plm</pExt>
<CppX>*.cpp</CppX>
<nMigrate>0</nMigrate>
</Extensions>
<DateTime>
<dwLowDateTime>0</dwLowDateTime>
<dwHighDateTime>0</dwHighDateTime>
</DateTime>
<Target>
<TargetName>LYNX_XERIUS_APRR_CPU2006_0091</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<TargetOption>
<OPTTT>
<gFlags>0</gFlags>
</OPTTT>
<AAA>
<SetRegEntry>
<Number>0</Number>
</SetRegEntry>
</AAA>
<Breakpoint>
<Bp>
<Number>0</Number>
</Bp>
<Bp>
<Number>1</Number>
</Bp>
<Bp>
<Number>2</Number>
</Bp>
<Bp>
<Number>3</Number>
</Bp>
<Bp>
<Number>4</Number>
</Bp>
</Breakpoint>
<Tracepoint>
<THDelay>0</THDelay>
</Tracepoint>
<DebugFlag>
<trace>0</trace>
</DebugFlag>
<LintExecutable></LintExecutable>
</TargetOption>
</Target>
<Target>
<TargetName>Debug</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<TargetOption>
<OPTTT>
<gFlags>0</gFlags>
</OPTTT>
<AAA>
<SetRegEntry>
<Number>0</Number>
</SetRegEntry>
</AAA>
<Breakpoint>
<Bp>
<Number>0</Number>
</Bp>
<Bp>
<Number>1</Number>
</Bp>
<Bp>
<Number>2</Number>
</Bp>
<Bp>
<Number>3</Number>
</Bp>
<Bp>
<Number>4</Number>
</Bp>
</Breakpoint>
<Tracepoint>
<THDelay>0</THDelay>
</Tracepoint>
<DebugFlag>
<trace>0</trace>
</DebugFlag>
<LintExecutable></LintExecutable>
</TargetOption>
</Target>
<Target>
<TargetName>LYNX_HERMES_APRR_SERIE_200</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<TargetOption>
<OPTTT>
<gFlags>0</gFlags>
</OPTTT>
<AAA>
<SetRegEntry>
<Number>0</Number>
</SetRegEntry>
</AAA>
<Breakpoint>
<Bp>
<Number>0</Number>
</Bp>
<Bp>
<Number>1</Number>
</Bp>
<Bp>
<Number>2</Number>
</Bp>
<Bp>
<Number>3</Number>
</Bp>
<Bp>
<Number>4</Number>
</Bp>
</Breakpoint>
<Tracepoint>
<THDelay>0</THDelay>
</Tracepoint>
<DebugFlag>
<trace>0</trace>
</DebugFlag>
<LintExecutable></LintExecutable>
</TargetOption>
</Target>
<Group>
<GroupName>::CMSIS</GroupName>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>1</RteFlg>
</Group>
</Project>
Here's my XSLT :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="urn:TestNamespace" >
<xsl:output indent="yes" />
<xsl:strip-space elements="*"/>
<xsl:template match="text()[not(string-length(normalize-space()))]"/>
<xsl:template match="Project">
<xsl:copy>
<xsl:apply-templates select="Target">
<xsl:sort select="TargetName"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<!-- global template to copy everything that doesn't match the other templates -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I got a XML file sorted by TargetName as output, but with only Target nodes....
How can I setup the select case to keep the unfiltered nodes ?
I also tested with :
<xsl:copy>
<xsl:apply-templates select="#*"/>
<xsl:apply-templates select="Target">
<xsl:sort select="TargetName"/>
</xsl:apply-templates>
</xsl:copy>
In this case, all data is kept but there is no sorting ?
I will appreciate some explanation to improve my knowledge.
Best Regards
One approach is:
<xsl:template match="Project">
<xsl:copy>
<xsl:apply-templates select="node()">
<xsl:sort select="TargetName" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
Why is your solution not working:
<xsl:apply-templates select="Target">
You select only Target to apply further.
I would probably do this (using XSLT 2.0):
<xsl:template match="Project">
<xsl:copy>
<xsl:for-each-group select="*" group-adjacent="node-name()">
<xsl:apply-templates>
<xsl:sort select="TargetName"/>
</xsl:apply-templates>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
on the assumption that sorting groups of elements other than Target elements does no harm. But it would probably be cleaner to have a conditional (xsl:choose) inside the xsl:for-each-group so the sorting is only done when test="self::Target".

WSS4J Invalid Security header -- wish to turn off "ec" prefix in InclusiveNamespace element

When hitting a producer web service with the following SOAP request I get a "invalid security header" message returned. When my test case with Oracle JDK 7, which uses JAX-WS RI 2.2.4-b01, it works fine.
I have to use WSS4j 1.6.0 and IBM JDK 6 as I am on Websphere -- I think the problem is with JAX-WS RI 2.1.6 that comes with IBM JDK 6.
I am trying to get my InclusiveNamspaces to look as follows without the "ec" prefix, as I notice this is one of the things different in the XML request shown below.
<S:Header>
<wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
S:mustUnderstand="1">
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
Id="SIG-A45B0A5E750A47B9AE6EC49A362DB055">
<ds:SignedInfo>
<ds:CanonicalizationMethod
Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#WithComments" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#TS-1">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#"
PrefixList="wsse S urn urn1" />
But instead it is coming out with the "ec" prefix
<ec:InclusiveNamespaces PrefixList="wsse S urn urn1" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" />
I have tried this in my code but it does not remove it. Any ideas?
org.apache.xml.security.Init.init();
org.apache.xml.security.utils.ElementProxy.setDefaultPrefix("http://www.w3.org/2001/10/xml-exc-c14n#", "");
Here is a request that works when using Oracle JDK 7, notice that it is using JAX-WS RI 2.2.4-b01
POST /airp/aca/a2a/1095BC_Transmission_AATS2016 HTTP/1.1
Accept: text/xml, multipart/related
Content-Type: multipart/related;start="
<rootpart * d2bbd41-479c-4851-b6fb-5de42ba6573f #
example.jaxws.sun.com>
";type="application/xop+xml";boundary="uuid:6d2bbd41-479c-4851-b6fb-5de42ba6573f";start-info="text/xml"
SOAPAction: "BulkRequestTransmitter"
User-Agent: JAX-WS RI 2.2.4-b01
Host: la.www4.irs.gov
Connection: keep-alive
Content-Length: 325083
--uuid:6d2bbd41-479c-4851-b6fb-5de42ba6573f
Content-Id:
<rootpart * d2bbd41-479c-4851-b6fb-5de42ba6573f #
example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:us:gov:treasury:irs:ext:aca:air:7.0" xmlns:urn1="urn:us:gov:treasury:irs:common">
<S:Header>
<wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
S:mustUnderstand="1">
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
Id="SIG-DEE23B9A923D4A3CA3211DF2A3CD881A">
<ds:SignedInfo>
<ds:CanonicalizationMethod
Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#WithComments"></ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod>
<ds:Reference URI="#TS-1">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#"
PrefixList="wsse S urn urn1"></InclusiveNamespaces>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod>
<ds:DigestValue>removed=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#id-4A79A4500D834A1688F0255D34F4B90A">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#"
PrefixList="S urn1"></InclusiveNamespaces>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod>
<ds:DigestValue>removed=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#id-1447A9BC79B048418D358EF9F861A302">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#"
PrefixList="S urn urn1"></InclusiveNamespaces>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod>
<ds:DigestValue>removed=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>removed==</ds:SignatureValue>
<ds:KeyInfo Id="KI-F84482F8FD684AF9811FCEA580F9FF93">
<wsse:SecurityTokenReference
wsu:Id="STR-71DE006212BB4C9FA21F3F59F79737CA">
<wsse:KeyIdentifier
EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">removed</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
<wsu:Timestamp wsu:Id="TS-1">
<wsu:Created>2016-01-08T23:00:48.578Z</wsu:Created>
<wsu:Expires>2016-01-09T00:00:48.578Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
Here is the request using IBM JDK 6 that has JAX-WS 2.1 -- the only difference I can see is that it uses "ec" prefix and expressly states it's UTF-8
POST /airp/aca/a2a/1095BC_Transmission_AATS2016 HTTP/1.1
Soapaction:
"BulkRequestTransmitter"
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-type:
multipart/related;start="
<rootpart * e-488d-80b8-4a137e7cb54e # example.jaxws.sun.com>
";type="application/xop+xml";boundary="uuid:94066996-016e-488d-80b8-4a137e7cb54e";start-info="text/xml"
User-Agent: JAX-WS RI 2.1.6 in JDK 6
Host: la.www4.irs.gov
Connection: keep-alive
Content-Length: 325122
--uuid:94066996-016e-488d-80b8-4a137e7cb54e
Content-Id:
<rootpart * e-488d-80b8-4a137e7cb54e # example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:us:gov:treasury:irs:ext:aca:air:7.0" xmlns:urn1="urn:us:gov:treasury:irs:common">
<S:Header>
<wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
S:mustUnderstand="1">
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
Id="SIG-2533902FF05A4C3EAD4DF4394DDC7232">
<ds:SignedInfo>
<ds:CanonicalizationMethod
Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#WithComments"></ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod>
<ds:Reference URI="#TS-1">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces
xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"
PrefixList="wsse S urn urn1"></ec:InclusiveNamespaces>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod>
<ds:DigestValue>removed=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#id-7E93AD40DB804D8D9241DE569606EC96">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces
xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"
PrefixList="S urn1"></ec:InclusiveNamespaces>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod>
<ds:DigestValue>removed=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#id-2F77BCB77A484ABAB2FF110E580E2DD3">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces
xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"
PrefixList="S urn urn1"></ec:InclusiveNamespaces>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod>
<ds:DigestValue>removed=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>removed==</ds:SignatureValue>
<ds:KeyInfo Id="KI-7A496D73BB5342EAA06616B8AF4FDCB0">
<wsse:SecurityTokenReference
wsu:Id="STR-BF7E3246416240B5B45DA733BC718073">
<wsse:KeyIdentifier
EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">removed</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
<wsu:Timestamp wsu:Id="TS-1">
<wsu:Created>2016-01-08T23:04:33.001Z</wsu:Created>
<wsu:Expires>2016-01-09T00:04:33.001Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>

xsl:for-each-group positional grouping flat xml to hierarchical

I have a flat xml file that needs to be converted to hierarchical. I used the nested grouping idea from here xsl:for-each-group help needed. It's working for the most part except for a couple of issues:
1) The elements root1 and root2 are not showing up.
2) The location of element NFActy is incorrect. The first NFActy should be between the 2 Rot elements.
3) The Duty & NFActy elements are treated as one group for calculating the SequenceCount.
4) For Leg elements each set of Leg elements within one duty should be grouped for SequenceCount for leg elements.
Any help is really appreciated.
Thanks.
Input XML
<root>
<root1>1234</root1>
<root2>5678</root2>
<Schedule>
<a>line 1</a>
<b>line 2</b>
<c>line 3</c>
</Schedule>
<Rot>
<d>line 4</d>
<e>line 5</e>
<f>line 6</f>
<g>line 7</g>
</Rot>
<Duty>
<h>line 8</h>
<i>line 9</i>
<j>line 10</j>
<k>line 11</k>
<l>line 12</l>
</Duty>
<Leg>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</Leg>
<Leg>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</Leg>
<NFActy>
<d>line 214</d>
<e>line 215</e>
<f>line 216</f>
<g>line 217</g>
</NFActy>
<Rot>
<d>line 19</d>
<e>line 20</e>
<f>line 21</f>
<g>line 22</g>
</Rot>
<Duty>
<h>line 23</h>
<i>line 24</i>
<j>line 25</j>
<k>line 26</k>
<l>line 27</l>
</Duty>
<Leg>
<m>line 28</m>
<n>line 29</n>
<o>line 30</o>
</Leg>
<Leg>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</Leg>
<NFActy>
<d>line 224</d>
<e>line 225</e>
<f>line 226</f>
<g>line 227</g>
</NFActy>
Desired Output XML
<root>
<root1>1234</root1>
<root2>5678</root2>
<Schedule>
<a>line 1</a>
<b>line 2</b>
<c>line 3</c>
<Rot>
<d>line 4</d>
<e>line 5</e>
<f>line 6</f>
<g>line 7</g>
<Duty>
<SequenceCount>1</SequenceCount>
<h>line 8</h>
<i>line 9</i>
<j>line 10</j>
<k>line 11</k>
<l>line 12</l>
<Leg>
<SequenceCount>1</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</Leg>
<Leg>
<SequenceCount>2</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</Leg>
</Duty>
</Rot>
<NFActy>
<SequenceCount>2</SequenceCount>
<d>line 214</d>
<e>line 215</e>
<f>line 216</f>
<g>line 217</g>
</NFActy>
<Rot>
<d>line 19</d>
<e>line 20</e>
<f>line 21</f>
<g>line 22</g>
<Duty>
<SequenceCount>3</SequenceCount>
<h>line 23</h>
<i>line 24</i>
<j>line 25</j>
<k>line 26</k>
<l>line 27</l>
<Leg>
<SequenceCount>1</SequenceCount>
<m>line 28</m>
<n>line 29</n>
<o>line 30</o>
</Leg>
<Leg>
<SequenceCount>2</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
/Leg>
</Duty>
</Rot>
<NFActy>
<SequenceCount>4</SequenceCount>
<d>line 224</d>
<e>line 225</e>
<f>line 226</f>
<g>line 227</g>
</NFActy>
</Schedule>
My XSL
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="fn" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"
exclude-result-prefixes="xs fn">
<xsl:output indent="yes" />
<xsl:template match="/">
<xsl:for-each-group select="*" group-starting-with="root">
<root>
<xsl:for-each-group select="*" group-starting-with="*[name(.)='Schedule']">
<xsl:choose>
<xsl:when test="name(.)='Schedule'">
<Schedule>
<xsl:apply-templates />
<xsl:for-each-group select="current-group()" group-starting-with="*[name(.)='Rot']">
<xsl:choose>
<xsl:when test="name(.)='Rot'">
<Rot>
<xsl:apply-templates />
<xsl:for-each-group select="current-group()" group-starting-with="*[name(.)='Duty']">
<xsl:choose>
<xsl:when test="name(.)='Duty'">
<Duty>
<xsl:element name="SequenceCount"><xsl:number count="Duty|NFActy" level="any"/></xsl:element>
<xsl:apply-templates />
<xsl:for-each-group select="current-group()" group-starting-with="*[name(.)='Leg']">
<xsl:choose>
<xsl:when test="name(.)='Leg'">
<Leg>
<xsl:element name="SequenceCount"><xsl:number value="position() - 1"/></xsl:element>
<xsl:apply-templates />
</Leg>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</Duty>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</Rot>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
<xsl:for-each-group select="current-group()" group-starting-with="*[name(.)='NFActy']">
<xsl:choose>
<xsl:when test="name(.)='NFActy'">
<NFActy>
<xsl:element name="SequenceCount"><xsl:number count="Duty|NFActy" level="any"/></xsl:element>
<xsl:apply-templates />
</NFActy>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</Schedule>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</root>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Here is my edit of your code, you need to make sure you process all elements at the same time and not as you had with sequential for-each-group.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"
exclude-result-prefixes="xs">
<xsl:output indent="yes" />
<xsl:template match="root">
<xsl:copy>
<xsl:for-each-group select="*" group-starting-with="Schedule">
<xsl:choose>
<xsl:when test="self::Schedule">
<Schedule>
<xsl:apply-templates />
<xsl:for-each-group select="current-group() except ." group-starting-with="Rot | NFActy">
<xsl:choose>
<xsl:when test="self::Rot | self::NFActy">
<xsl:copy>
<xsl:if test="self::NFActy">
<SequenceCount><xsl:number count="Duty | NFActy" level="any"/></SequenceCount>
</xsl:if>
<xsl:apply-templates />
<xsl:for-each-group select="current-group() except ." group-starting-with="Duty">
<xsl:choose>
<xsl:when test="self::Duty">
<xsl:copy>
<SequenceCount><xsl:number count="Duty | NFActy" level="any"/></SequenceCount>
<xsl:apply-templates />
<xsl:for-each-group select="current-group() except ." group-starting-with="Leg">
<xsl:choose>
<xsl:when test="self::Leg">
<Leg>
<SequenceCount><xsl:number value="position()"/></SequenceCount>
<xsl:apply-templates />
</Leg>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</Schedule>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
When I apply above stylesheet with Saxon 9.5 to the input
<root>
<root1>1234</root1>
<root2>5678</root2>
<Schedule>
<a>line 1</a>
<b>line 2</b>
<c>line 3</c>
</Schedule>
<Rot>
<d>line 4</d>
<e>line 5</e>
<f>line 6</f>
<g>line 7</g>
</Rot>
<Duty>
<h>line 8</h>
<i>line 9</i>
<j>line 10</j>
<k>line 11</k>
<l>line 12</l>
</Duty>
<Leg>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</Leg>
<Leg>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</Leg>
<NFActy>
<d>line 214</d>
<e>line 215</e>
<f>line 216</f>
<g>line 217</g>
</NFActy>
<Rot>
<d>line 19</d>
<e>line 20</e>
<f>line 21</f>
<g>line 22</g>
</Rot>
<Duty>
<h>line 23</h>
<i>line 24</i>
<j>line 25</j>
<k>line 26</k>
<l>line 27</l>
</Duty>
<Leg>
<m>line 28</m>
<n>line 29</n>
<o>line 30</o>
</Leg>
<Leg>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</Leg>
<NFActy>
<d>line 224</d>
<e>line 225</e>
<f>line 226</f>
<g>line 227</g>
</NFActy>
</root>
I get the result
<root>
<root1>1234</root1>
<root2>5678</root2>
<Schedule>
<a>line 1</a>
<b>line 2</b>
<c>line 3</c>
<Rot>
<d>line 4</d>
<e>line 5</e>
<f>line 6</f>
<g>line 7</g>
<Duty>
<SequenceCount>1</SequenceCount>
<h>line 8</h>
<i>line 9</i>
<j>line 10</j>
<k>line 11</k>
<l>line 12</l>
<Leg>
<SequenceCount>1</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</Leg>
<Leg>
<SequenceCount>2</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</Leg>
</Duty>
</Rot>
<NFActy>
<SequenceCount>2</SequenceCount>
<d>line 214</d>
<e>line 215</e>
<f>line 216</f>
<g>line 217</g>
</NFActy>
<Rot>
<d>line 19</d>
<e>line 20</e>
<f>line 21</f>
<g>line 22</g>
<Duty>
<SequenceCount>3</SequenceCount>
<h>line 23</h>
<i>line 24</i>
<j>line 25</j>
<k>line 26</k>
<l>line 27</l>
<Leg>
<SequenceCount>1</SequenceCount>
<m>line 28</m>
<n>line 29</n>
<o>line 30</o>
</Leg>
<Leg>
<SequenceCount>2</SequenceCount>
<m>line 13</m>
<n>line 14</n>
<o>line 15</o>
</Leg>
</Duty>
</Rot>
<NFActy>
<SequenceCount>4</SequenceCount>
<d>line 224</d>
<e>line 225</e>
<f>line 226</f>
<g>line 227</g>
</NFActy>
</Schedule>
</root>

wso2 cache mediator response in binary (it should be XML)

I'm learning about wso2 ESB 4.6.0. I'm studying right now about mediators. I implemented cache mediator as below.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="cacheProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<cache id="myCache" scope="per-mediator" collector="false" hashGenerator="org.wso2.caching.digest.DOMHASHGenerator" timeout="3" maxMessageSize="1000">
<implementation type="memory" maxSize="1000"/>
</cache>
<send>
<endpoint>
<address uri="http://localhost:44444/ws/MediatorsWS"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<cache id="myCache" scope="per-mediator" collector="true"/>
<send/>
</outSequence>
<endpoint>
<address uri="http://localhost:44444/ws/MediatorsWS"/>
</endpoint>
</target>
<publishWSDL uri="http://localhost:44444/ws/MediatorsWS?wsdl"/>
<description></description>
</proxy>
It redirects to a webservice implemented with JAX-WS receiving SOAP 1.1. Here is the wsdl:
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:tns="http://clone.ws.wso2lessons/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://clone.ws.wso2lessons/">
<wsdl:types>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="unqualified">
<xsd:import namespace="http://clone.ws.wso2lessons/" schemaLocation="cacheProxy?xsd=http://localhost:44444/ws/MediatorsWS?xsd=1.xsd"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="receiveMessage">
<wsdl:part name="parameters" element="tns:receiveMessage"/>
</wsdl:message>
<wsdl:message name="receiveMessageResponse">
<wsdl:part name="parameters" element="tns:receiveMessageResponse"/>
</wsdl:message>
<wsdl:message name="replyMessage">
<wsdl:part name="parameters" element="tns:replyMessage"/>
</wsdl:message>
<wsdl:message name="replyMessageResponse">
<wsdl:part name="parameters" element="tns:replyMessageResponse"/>
</wsdl:message>
<wsdl:portType name="cacheProxyPortType">
<wsdl:operation name="receiveMessage">
<wsdl:input message="tns:receiveMessage" wsaw:Action="http://clone.ws.wso2lessons/MediatorsWS/receiveMessageRequest"/>
<wsdl:output message="tns:receiveMessageResponse" wsaw:Action="http://clone.ws.wso2lessons/MediatorsWS/receiveMessageResponse"/>
</wsdl:operation>
<wsdl:operation name="replyMessage">
<wsdl:input message="tns:replyMessage" wsaw:Action="http://clone.ws.wso2lessons/MediatorsWS/replyMessageRequest"/>
<wsdl:output message="tns:replyMessageResponse" wsaw:Action="http://clone.ws.wso2lessons/MediatorsWS/replyMessageResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="cacheProxySoap11Binding" type="tns:cacheProxyPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="receiveMessage">
<soap:operation soapAction="" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="replyMessage">
<soap:operation soapAction="" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="cacheProxySoap12Binding" type="tns:cacheProxyPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="receiveMessage">
<soap12:operation soapAction="" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="replyMessage">
<soap12:operation soapAction="" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="cacheProxyHttpBinding" type="tns:cacheProxyPortType">
<http:binding verb="POST"/>
<wsdl:operation name="receiveMessage">
<http:operation location="receiveMessage"/>
<wsdl:input>
<mime:content type="text/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="replyMessage">
<http:operation location="replyMessage"/>
<wsdl:input>
<mime:content type="text/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="cacheProxy">
<wsdl:port name="cacheProxyHttpSoap11Endpoint" binding="tns:cacheProxySoap11Binding">
<soap:address location="http://PCPPTCERTDEV01:8280/services/cacheProxy.cacheProxyHttpSoap11Endpoint"/>
</wsdl:port>
<wsdl:port name="cacheProxyHttpsSoap11Endpoint" binding="tns:cacheProxySoap11Binding">
<soap:address location="https://PCPPTCERTDEV01:8243/services/cacheProxy.cacheProxyHttpsSoap11Endpoint"/>
</wsdl:port>
<wsdl:port name="cacheProxyHttpsSoap12Endpoint" binding="tns:cacheProxySoap12Binding">
<soap12:address location="https://PCPPTCERTDEV01:8243/services/cacheProxy.cacheProxyHttpsSoap12Endpoint"/>
</wsdl:port>
<wsdl:port name="cacheProxyHttpSoap12Endpoint" binding="tns:cacheProxySoap12Binding">
<soap12:address location="http://PCPPTCERTDEV01:8280/services/cacheProxy.cacheProxyHttpSoap12Endpoint"/>
</wsdl:port>
<wsdl:port name="cacheProxyHttpsEndpoint" binding="tns:cacheProxyHttpBinding">
<http:address location="https://PCPPTCERTDEV01:8243/services/cacheProxy.cacheProxyHttpsEndpoint"/>
</wsdl:port>
<wsdl:port name="cacheProxyHttpEndpoint" binding="tns:cacheProxyHttpBinding">
<http:address location="http://PCPPTCERTDEV01:8280/services/cacheProxy.cacheProxyHttpEndpoint"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
When I send a message to operation replyMessage, the response message is cached succesfully (there is a System.out.println() on the java method, which is not called at the cache timeframe). However, the returned message I get is this:
<axis2ns27:binary xmlns:axis2ns27="http://ws.apache.org/commons/ns/payload">PD94bWwgdmVyc2lvbj0iMS4wIiA/PjxTOkVudmVsb3BlIHhtbG5zOlM9Imh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3NvYXAvZW52ZWxvcGUvIj48UzpCb2R5PjxuczI6cmVwbHlNZXNzYWdlUmVzcG9uc2UgeG1sbnM6bnMyPSJodHRwOi8vY2xvbmUud3Mud3NvMmxlc3NvbnMvIj48cmV0dXJuPmhlbGxvIHRoZXJlIHJlc3BvbmRpZGEuPC9yZXR1cm4+PC9uczI6cmVwbHlNZXNzYWdlUmVzcG9uc2U+PC9TOkJvZHk+PC9TOkVudmVsb3BlPg==</axis2ns27:binary>
If I don't use this mediator, message is returned correctly. What am I missing here?
we use passthrough transport, it doesnt build the message..Can you switch back to NIO transport and check?

Resources