【发布时间】:2016-12-19 08:27:24
【问题描述】:
我正在尝试通过 XSLT 转换 XML 文件。 输出 XML 需要包含元素作为属性。
我的输入文件如下所示:
<queryResponse>
<entity>
<DevicesDTO>
<name>value</name>
<type>value</type>
<manufacturersNrs>
<manufacturersNr>value</manufacturersNr>
</manufacturersNrs>
</DevicesDTO>
</entity>
</queryResponse>
我的输出应该是这样的:
<Data>
<Device name=xxx type=xxxx manufacturersNr=xxx />
</Data>
到目前为止,我已经成功地转换了我的 xml 并将名称和类型作为属性。 但是,manufacturersNrs 中包含了manufacturersNr,我不知道如何将其包含在它上面的节点中。
我的 xslt 文件现在看起来像这样:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="queryResponse">
<Data>
<xsl:apply-templates/>
</Data>
</xsl:template>
<xsl:template match="devicesDTO">
<Device>
<xsl:for-each select="*">
<xsl:attribute name="{name()}">
<xsl:value-of select="text()"/>
</xsl:attribute>
</xsl:for-each>
</Device>
</xsl:template>
</xsl:stylesheet>
对于一个完整的 xslt 新手有什么提示吗? 我现在拥有的东西是我从各种来源拼凑而成的,所以如果我需要完全重写......就这样吧。
【问题讨论】:
标签: xml xslt transformation