【问题标题】:Transforming ADODB.RecordSet xml using XSLT 1.0, unable to rename element z:row使用 XSLT 1.0 转换 ADODB.RecordSet xml,无法重命名元素 z:row
【发布时间】:2019-09-25 00:19:45
【问题描述】:

我需要将 ADODB.RecordSet 生成的 xml 转换为另一个 xml。除了这一个元素之外,一切都按预期工作。

XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/xml">
    <xsl:element name="xml">
        <xsl:element name="rows">
            <xsl:for-each select="/xml/rs:data/z:row">
                <xsl:copy>
                    <xsl:apply-templates select="@* | node()"/>
                </xsl:copy>
            </xsl:for-each>
        </xsl:element>
    </xsl:element>
</xsl:template>
<xsl:template match="@*">
    <xsl:choose>
        <xsl:when test="name()='z:row'">
            <xsl:element name="row">
                <xsl:value-of select="."/>
            </xsl:element>
        </xsl:when>
        <xsl:otherwise>
            <xsl:element name="{name()}">
                <xsl:value-of select="."/>
            </xsl:element>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
<xsl:template match="z:row">
    <row>
        <xsl:apply-templates select="@*|node()"/>
    </row>
</xsl:template>
</xsl:stylesheet>

输入 XML:

<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<rs:data>
    <z:row skip1="A" number="1" id="Vend Slot 2"/>
    <z:row skip1="A" number="2" id="Vend Slot 3"/>
</rs:data>
</xml>

实际输出:

<xml>
<rows>
    <z:row xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
        <skip1>A</skip1>
        <number>1</number>
        <id>Vend Slot 2</id>
    </z:row>
    <z:row xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
        <skip1>A</skip1>
        <number>2</number>
        <id>Vend Slot 3</id>
    </z:row>
</rows>
</xml>

预期输出:

<xml>
<rows>
    <row>
        <skip1>A</skip1>
        <number>1</number>
        <id>Vend Slot 2</id>
    </row>
    <row>
        <skip1>A</skip1>
        <number>2</number>
        <id>Vend Slot 3</id>
    </row>
</rows>
</xml>

【问题讨论】:

    标签: xml xslt-1.0


    【解决方案1】:

    我让它工作了。这是我的工作 Xslt。

    <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:z="#RowsetSchema">
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
    <xsl:template match="*">
        <!-- remove element prefix (if any) -->
        <xsl:element name="rows">
            <xsl:for-each select="//z:row">
                <xsl:element name="row">
                    <!-- process attributes -->
                    <xsl:for-each select="@*">
                        <!-- remove attribute prefix (if any) -->
                        <xsl:element name="{local-name()}">
                            <xsl:value-of select="."/>
                        </xsl:element>
                    </xsl:for-each>
                </xsl:element>
            </xsl:for-each>
        </xsl:element>
    </xsl:template>
    </xsl:transform>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-26
      • 2010-12-16
      • 2013-04-06
      • 2021-09-19
      • 2012-05-31
      • 1970-01-01
      相关资源
      最近更新 更多