我有一些像这样的XML;我想写一个XSLT。我可以在哪里提取属性V.并生成这样的树结构。
PS . . ....Product Category . . . . . . . Product. . ....Financial Product Images . . .Product2. Other . . ........Customer Location Images . . . Service3.
<PV V="PS:Product Category:Product1" L="" H="" C="327" />
<PV V="PS:Financial Product Images:Product2" L="" H="" C="173" />
<PV V="Other:Customer Location Images:Service2" L="" H="" C="122" />
<PV V="PS:POS Product Images:Product3" L="" H="" C="109" />
<PV V="N/A" L="" H="" C="106" />
<PV V="Other:Customer Location Images:Service 3" L="" H="" C="98" />
任何人都可以帮助我,我是XSLT的新手
答案 0 :(得分:0)
您可以使用此XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/wrapper">
<wrapper2>
<xsl:apply-templates select="PV[starts-with(@V,'PS')]"/>
<xsl:apply-templates select="PV[starts-with(@V,'Other')]"/>
</wrapper2>
</xsl:template>
<xsl:template match="//PV">
<xsl:variable name="elementName1" select="substring-before(./@V,':')"/>
<xsl:variable name="elementName23" select="substring-after(./@V,':')"/>
<xsl:variable name="elementName2"
select="translate(substring-before($elementName23,':'), ' ', '_')"/>
<xsl:variable name="elementName3"
select="translate(substring-after($elementName23,':'), ' ', '_')"/>
<xsl:if test="not($elementName1 = '')">
<xsl:element name="{$elementName1}">
<xsl:element name="{$elementName2}">
<xsl:element name="{$elementName3}"> </xsl:element>
</xsl:element>
</xsl:element>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
标记名称不能包含空格,因此您需要用其他字符替换它们。这是通过用'_'替换空格来完成的。