转变 ADODB.使用 XSLT 1.0 的记录集 xml,无法重命名元素 z:row



我需要转换ADODB生成的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>

我让它工作了。这是我的工作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>

最新更新