重复标记的xml到xml转换
我是编写XSL的新手。10年前我熟悉使用DOM解析器处理XML,但技术发生了变化。我想我仍然可以用JavaDOM解析器来完成这项工作,但这将增加系统的开销 我有以下格式的源XML。标记“值”的出现是可变的。我需要将其转换为第二种xml格式 XML源:重复标记的xml到xml转换,xml,xslt,Xml,Xslt,我是编写XSL的新手。10年前我熟悉使用DOM解析器处理XML,但技术发生了变化。我想我仍然可以用JavaDOM解析器来完成这项工作,但这将增加系统的开销 我有以下格式的源XML。标记“值”的出现是可变的。我需要将其转换为第二种xml格式 XML源: <Part> <PartNumber>XYZ</PartNumber> <ProductLines> <Value>P58</Value>
<Part>
<PartNumber>XYZ</PartNumber>
<ProductLines>
<Value>P58</Value>
<Value>P84</Value>
<Value>P88</Value>
<Value>P99</Value>
</ProductLines>
</Part>
XYZ
P58
P84
P88
P99
XML目标到
<Part>
<PartNumber>XYZ</PartNumber>
<ProductLines>P58,P84,P88,P99</ProductLines>
</Part>
XYZ
第58页,第84页,第88页,第99页
我正在尝试以下XSL,但不起作用:需要XML专家的建议
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">
<xsl:output method="xml"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"></xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="ProductLines">
<xsl:for-each select="Value">
<xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</xsl:template>
<xsl:template match="ProductLines/node()"/>
</xsl:stylesheet>
您可以使用类似的方法来连接这些值:
<xsl:variable name="concatenated_value">
<xsl:for-each select="Value">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">
<xsl:value-of select="','"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
什么“不起作用”?你能详细说明具体问题吗?这通常有助于让你更接近解决方案。是的,这是完美的。