N
Nutshell
Hi,
I would like to add an attribute to the child node if it is the only child
node. The problem is I am not getting the correct count of child nodes with
this template:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput method="xml" indent="yes" encoding="UTF-8" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:if test="name()='par' and count(parent::node()) = 1">
<xsl:attribute name="repeatCount">
<xsl:text>1</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Here, the 'par' node is the current child node and I would like to check
something like: if parent node of the current 'par' node has only one 'par'
node then add 'repeatCount' attribute to the only 'par' child node. But the
condition
<xsl:if test="name()='par' and count(parent::node()) = 1"> does not work for
me. What am I doing wrong in this condition?
Btw, I am using Xalan.
Thx, in advance!
I would like to add an attribute to the child node if it is the only child
node. The problem is I am not getting the correct count of child nodes with
this template:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput method="xml" indent="yes" encoding="UTF-8" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:if test="name()='par' and count(parent::node()) = 1">
<xsl:attribute name="repeatCount">
<xsl:text>1</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Here, the 'par' node is the current child node and I would like to check
something like: if parent node of the current 'par' node has only one 'par'
node then add 'repeatCount' attribute to the only 'par' child node. But the
condition
<xsl:if test="name()='par' and count(parent::node()) = 1"> does not work for
me. What am I doing wrong in this condition?
Btw, I am using Xalan.
Thx, in advance!