Xslt 1.0 XSLT:需要将名称-值对内容转换为XML
我是XSLT新手。我需要将包含名称-值对的XML转换为目标XML。 我需要生成一个目标XML,其中每个FieldName是一个元素名,它的值是FieldValue。请在下面找到我需要的输出。 提前谢谢你的帮助 源XML:Xslt 1.0 XSLT:需要将名称-值对内容转换为XML,xslt-1.0,xslt-2.0,Xslt 1.0,Xslt 2.0,我是XSLT新手。我需要将包含名称-值对的XML转换为目标XML。 我需要生成一个目标XML,其中每个FieldName是一个元素名,它的值是FieldValue。请在下面找到我需要的输出。 提前谢谢你的帮助 源XML: 模式 订单头 命令 1234 模式 订单项 项目 1. 数量 10 模式 订单项 项目 2. 数量 20 您似乎希望将第一个记录子项作为容器元素进行处理,并且要按照您的描述转换以下同级项: <xsl:stylesheet xmlns:xsl="http://www.w
模式
订单头
命令
1234
模式
订单项
项目
1.
数量
10
模式
订单项
项目
2.
数量
20
您似乎希望将第一个记录
子项作为容器元素进行处理,并且要按照您的描述转换以下同级项:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="SC">
<xsl:copy>
<xsl:apply-templates select="*/Record[1]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="SC/*/Record[1]">
<xsl:element name="{FieldValue}">
<xsl:apply-templates select="following-sibling::Record"/>
</xsl:element>
</xsl:template>
<xsl:template match="SC/*/Record[position() gt 1]">
<xsl:element name="{FieldName}">
<xsl:value-of select="FieldValue"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
您似乎希望将第一个
记录
子项作为容器元素进行处理,并且要按照您的描述转换以下同级项:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="SC">
<xsl:copy>
<xsl:apply-templates select="*/Record[1]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="SC/*/Record[1]">
<xsl:element name="{FieldValue}">
<xsl:apply-templates select="following-sibling::Record"/>
</xsl:element>
</xsl:template>
<xsl:template match="SC/*/Record[position() gt 1]">
<xsl:element name="{FieldName}">
<xsl:value-of select="FieldValue"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
这是另一个类似于Martin的选项
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Header|Detail">
<xsl:element name="{Record[1]/FieldValue}">
<xsl:apply-templates select="Record[position()>1]"/>
</xsl:element>
</xsl:template>
<xsl:template match="Record">
<xsl:element name="{FieldName}">
<xsl:value-of select="FieldValue"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
这是另一个类似于Martin的选项
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Header|Detail">
<xsl:element name="{Record[1]/FieldValue}">
<xsl:apply-templates select="Record[position()>1]"/>
</xsl:element>
</xsl:template>
<xsl:template match="Record">
<xsl:element name="{FieldName}">
<xsl:value-of select="FieldValue"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>