Hi List.
I have an XSL that uses identity template to filter some nodes based on
a specific value.
This does work.
Now, as my count of node has changed, I should modify one of upper nodes
attribute so that it reflects this count.
But how ?
Here is my xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "xml" encoding="UTF-8" indent="no" />
<xsl:key name="keyHidden" match="//table/header/col/*[(_at_)hide =
1]" use="name()"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates
select="@*|node()[not(key('keyHidden',name()) != '')]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="header">
<!-- we have to change the value of col attribute to
reflect the real number of sub nodes once hidden columns have been
filtered out -->
<!-- Count how many sub nodes we have -->
<xsl:variable name="colCount">
<xsl:value-of select="@col - count(col/*[(_at_)hide =
1])"/>
</xsl:variable>
<!-- That's the idea, but it doesn't work ... -->
<xsl:attribute name="col">
<xsl:value-of select="$colCount"/>
</xsl:attribute>
<xsl:copy>
<xsl:apply-templates
select="@*[not(name()='@col')]|node()[not(key('keyHidden',name()) !=
'')]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
And here is a sample xml data
The @col attribute in <header> is 12 and should be set to 8 as the nodes
with attribute @hide=1 below will be removed
<application>
<table>
<data>
</data>
<header bgcolor="#505E87" col="12" fit="1" ic50="1" type="8">
<info>
<number>259</number>
<family>2</family>
<type>8</type>
<theader>Here is a header</theader>
<tfooter/>
</info>
<col>
<N112 dataalign="left" headeralign="left" sub="1">Column
1</N112>
<N100 dataalign="left" headeralign="left" sub="1">Column
2</N100>
<N101 dataalign="left" headeralign="left" sub="1">Column 3
</N101>
<N308 dataalign="right" headeralign="right" hide="1"
sub="1"> Column 4 </N308>
<N107 dataalign="center" headeralign="center" sub="1" >
Column 5</N107>
<P2010 dataalign="center" headeralign="center" sub="1"
Column 6</P2010>
<N109 dataalign="center" headeralign="center" sub="1">Column
7</N109>
<N307 dataalign="right" headeralign="right" hide="1"
sub="1">Column 8</N307>
<N206 dataalign="right" headeralign="right" hide="1"
sub="1">Column 9</N206>
<N310 dataalign="center" headeralign="center" hide="1"
sub="1">Column 10</N310>
<N108 dataalign="center" headeralign="center" sub="1">Column
11</N108>
<N105 dataalign="right" headeralign="right" sub="3">Column
12</N105>
</col>
</header>
</table>
</application>
Any clue ?
Thanks a lot in advance,
Best regards,
Fabien
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--