[英]How to concat some value in the existing value of a xml using xslt
Apologises if duplicate. 如果重复则表示歉意。 I want to perform a concat operation on the values of the xml elements. 我想对xml元素的值执行concat操作。
I have xml say Input.xml
<collection>
<one>
<part>1</part>
</one>
<two>
<part>2</part>
</two>
<three>
<part>3</part>
</three>
</collection>
I want the output like : 我想要这样的输出:
<collection>
<one>
<part>001</part>
</one>
<two>
<part>002</part>
</two>
<three>
<part>003</part>
</three>
</collection>
how to write xslt for it 如何为它编写xslt
Quick hacky XSLT , tested it online it seems to work. Quick hacky XSLT,已在网上对其进行了测试,似乎可以正常工作。
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="@*|text()|comment()|processing-instruction">
</xsl:template>
<xsl:template match="//part">
<part>
<xsl:text>00</xsl:text>
<xsl:value-of select="."></xsl:value-of>
</part>
</xsl:template>
</xsl:stylesheet>
Your possible solution might be: 您可能的解决方案可能是:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="part">
<xsl:value-of select="format-number(., '000')"/>
</xsl:template>
<!-- identity copy -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Format the text in part
to a 3 digit number format 将文本part
格式化为3位数字格式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.