我对XSL概念非常陌生,我正在尝试为下面的XML创建一个XSLT,
<?xml version="1.0" encoding="UTF-8"?>
<row>
<c1>1234</c1>
<c2>A</c2>
<c2 m="1" s="2">321</c2>
<c2 m="1" s="3">654</c2>
<c2 m="1" s="4">098</c2>
<c2 m="2">B</c2>
<c2 m="3">C</c2>
<c2 m="3" s="2">123</c2>
<c2 m="4">5</c2>
<c3 />
</row>如果使用XSL进行转换,那么输出应该如下所示:
1234 A\321\654\098]B]C\123]5
我试着创建我自己的,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="row">
<array />
<xsl:apply-templates />
</xsl:template>
<xsl:template match="c1">
<data>
<xsl:attribute name="attribute">1</xsl:attribute>
<xsl:attribute name="value">
<xsl:number level="single" />
</xsl:attribute>
<xsl:attribute name="subvalue">1</xsl:attribute>
<xsl:value-of select="." />
</data>
</xsl:template>
<xsl:template match="c2">
<data>
<xsl:attribute name="attribute">1</xsl:attribute>
<xsl:attribute name="value">
<xsl:number level="single" />
</xsl:attribute>
<xsl:attribute name="subvalue">1</xsl:attribute>
<xsl:value-of select="." />
</data>
</xsl:template>
</xsl:stylesheet>但是我得到的输出如下,
1234 A 321 654 098 B C 123 5请帮助我创建XSL
发布于 2015-11-09 16:59:30
这一切都非常令人困惑。您的XSLT生成具有各种属性的<array>和<data>元素,但是在您想要的输出中没有这样的元素或属性。实际上,您的示例代码似乎与您想要的输出完全没有关系。
从一个例子中对需求进行逆向工程总是很困难的,但我尝试这样做:
row元素的子元素的字符串值@m1大于上一个@m1,则在字符串值之前加上“”F217
如果我的猜测接近目标,那么解决方案应该是这样的:
<xsl:template match="row">
<xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="row/*[@m1 > preceding-sibling::*[1]/@m1]">
<xsl:value-of select="concat(']', .)"/>
</xsl:template>
<xsl:template match="row/*[@m1 = preceding-sibling::*[1]/@m1]">
<xsl:value-of select="concat('\', .)"/>
</xsl:template>
<xsl:template match="row/*[not(@m1)]">
<xsl:value-of select="concat(' ', .)"/>
</xsl:template>https://stackoverflow.com/questions/33603193
复制相似问题