如何基于position()跳过xslt中的元素
这是我的xslt: 这一个工作,但只有当硬代码'1,2,'如何基于position()跳过xslt中的元素,xslt,Xslt,这是我的xslt: 这一个工作,但只有当硬代码'1,2,' <xsl:template match="row[contains('1,2,',concat(position(),','))]" 非工作xslt: <xsl:stylesheet version="1.0" exclude-result-prefixes="msxsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas
<xsl:template match="row[contains('1,2,',concat(position(),','))]"
非工作xslt:
<xsl:stylesheet version="1.0" exclude-result-prefixes="msxsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="positions"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="row[contains('1,2,',concat(position(),','))]" name="skiprow"/>
</xsl:stylesheet>
<xsl:stylesheet version="1.0" exclude-result-prefixes="msxsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="positions"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="row[contains('$positions',concat(position(),','))]" name="skiprow"/>
</xsl:stylesheet>
<xsl:template match="row[contains('$positions',concat(position(),','))]" name="skiprow"/>
这意味着参数必须以逗号字符开头和结尾
以下是完整的、经过更正的转换:
<xsl:template match="row>
<xsl:if test=
"not(contains($vPositions, concat(position(),',')))">
<xsl:call-template name="identity"/>
<xsl:if>
</xsl:template>
not(contains($vPositions, concat(',',position(),',')))
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="vPositions" select="',1,2,'"/>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="row">
<xsl:if test=
"not(contains($vPositions, concat(',',position(),',')))">
<xsl:call-template name="identity"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
太好了,效果很好。谢谢你给我指点逗号,我以前没想到。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="vPositions" select="'1,2,'"/>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="row">
<xsl:if test=
"not(contains($vPositions, concat(position(),',')))">
<xsl:call-template name="identity"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
<root>
<row>
<column1>7004275</column1>
<column2>NUVCFDK</column2>
</row>
<row>
<column1>1001459</column1>
<column2>CAN</column2>
<column3>12</column3>
<column4>646.80</column4>
<column5>23-06-2009</column5>
<column6>31-12-2009</column6>
<column7/>
</row>
<row>
<column1>1001461</column1>
<column2>CAN</column2>
<column3>1</column3>
<column4>9.50</column4>
<column5>23-06-2009</column5>
<column6>31-12-2009</column6>
<column7/>
</row>
</root>
<root>
<row>
<column1>1001461</column1>
<column2>CAN</column2>
<column3>1</column3>
<column4>9.50</column4>
<column5>23-06-2009</column5>
<column6>31-12-2009</column6>
<column7/>
</row>
</root>
not(contains($vPositions, concat(',',position(),',')))
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="vPositions" select="',1,2,'"/>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="row">
<xsl:if test=
"not(contains($vPositions, concat(',',position(),',')))">
<xsl:call-template name="identity"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>