Xslt 通过以递增的数目命名的节点进行迭代
我正在学习XSLT,我有以下XML示例:Xslt 通过以递增的数目命名的节点进行迭代,xslt,Xslt,我正在学习XSLT,我有以下XML示例: <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="transform.xsl"?> <ROWSET> <nazwa>nazwa d</nazwa> <ROW> <NAME>Kwota bieżąca</NAME> <SCHEDULE>0</SCHEDULE&
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="transform.xsl"?>
<ROWSET>
<nazwa>nazwa d</nazwa>
<ROW>
<NAME>Kwota bieżąca</NAME>
<SCHEDULE>0</SCHEDULE>
<UNDISPOSED>0</UNDISPOSED>
<FSUM>0</FSUM>
<DAYS>
<DAY1>5</DAY1>
<DAY2>4</DAY2>
<DAY3>3</DAY3>
<DAY4>2</DAY4>
<DAY5>1</DAY5>
</DAYS>
</ROW>
</ROWSET>
我不知道如何替换第1天、第2天等使其工作
DAY[$count]
不起作用…XPath地址/ROWSET/ROW/DAYS/*
将为您提供所有子元素,并按文档顺序获取它们。是否有需要按名称对其进行寻址的原因?XPath地址/ROWSET/ROW/DAYS/*
将为您提供所有子元素,并按文档顺序获取它们。您需要按名称对它们进行命名吗?在xslt 1中,您可以这样做:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="/">
<!-- ... just continue in processing... -->
<xsl:apply-templates select="ROWSET/ROW/DAYS/*"/>
</xsl:template>
<!-- ... if you find node with name starting with DAY put its content to the output -->
<xsl:template match="node()[starts-with(name(),'DAY')]">
<xsl:value-of select="." />
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
在XSLT2中,这可能更容易
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:value-of select="/ROWSET/ROW/DAYS/node()[starts-with(name(),'DAY')]" separator=" " />
</xsl:template>
</xsl:stylesheet>
在xslt 1中,可以执行以下操作:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="/">
<!-- ... just continue in processing... -->
<xsl:apply-templates select="ROWSET/ROW/DAYS/*"/>
</xsl:template>
<!-- ... if you find node with name starting with DAY put its content to the output -->
<xsl:template match="node()[starts-with(name(),'DAY')]">
<xsl:value-of select="." />
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
在XSLT2中,这可能更容易
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:value-of select="/ROWSET/ROW/DAYS/node()[starts-with(name(),'DAY')]" separator=" " />
</xsl:template>
</xsl:stylesheet>
查看元素。查看元素。