我是 XSLT 的新手,我得到的响应 XML 正在数组中显示,其中XML元素上存在命名空间冲突,我需要使其唯一进一步在另一个系统中使用。
下面是我尝试使用XSLT转换的响应XML,以及所需的结果,我希望在使用后缀或前缀进行XSLT转换后,使新输出XML文档中select id
from table
group by id
having count(distinct variant_id) > 1
的每个重复元素都是唯一的在元素上。
要转换的原始XML文档
<WorksheetServiceProperty>
期望的结果
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<GetWorksheetDetailExtraInfoFieldsResponse xmlns="http://webservices.whitespacews.com/">
<GetWorksheetDetailExtraInfoFieldsResult>
<ErrorCode>0</ErrorCode>
<ErrorDescription>Success</ErrorDescription>
<SuccessFlag>true</SuccessFlag>
<WorksheetServiceProperties>
<WorksheetServiceProperty>
<ExtensionData />
<WorksheetServiceID>42</WorksheetServiceID>
<ServicePropertyID>10</ServicePropertyID>
<ServicePropertyName>Job Completed</ServicePropertyName>
<ServicePropertyValue>Yes</ServicePropertyValue>
<ServicePropertyTypeID>4</ServicePropertyTypeID>
<ServicePropertyTypeName>List</ServicePropertyTypeName>
<ServicePropertyOrder>30</ServicePropertyOrder>
<ForMobile>true</ForMobile>
<ForPowerSuite>true</ForPowerSuite>
</WorksheetServiceProperty>
<WorksheetServiceProperty>
<ExtensionData />
<WorksheetServiceID>42</WorksheetServiceID>
<ServicePropertyID>15</ServicePropertyID>
<ServicePropertyName>Crew Comments</ServicePropertyName>
<ServicePropertyValue>Collected all items successfully</ServicePropertyValue>
<ServicePropertyTypeID>7</ServicePropertyTypeID>
<ServicePropertyTypeName>TextBox</ServicePropertyTypeName>
<ServicePropertyOrder>5</ServicePropertyOrder>
<ForMobile>true</ForMobile>
<ForPowerSuite>true</ForPowerSuite>
</WorksheetServiceProperty>
<WorksheetServiceProperty>
<ExtensionData />
<WorksheetServiceID>42</WorksheetServiceID>
<ServicePropertyID>16</ServicePropertyID>
<ServicePropertyName>Items To Be Collected</ServicePropertyName>
<ServicePropertyValue>Matress, bed frame, fridge</ServicePropertyValue>
<ServicePropertyTypeID>1</ServicePropertyTypeID>
<ServicePropertyTypeName>String</ServicePropertyTypeName>
<ServicePropertyOrder>2</ServicePropertyOrder>
<ForMobile>true</ForMobile>
<ForPowerSuite>true</ForPowerSuite>
</WorksheetServiceProperty>
</WorksheetServiceProperties>
</GetWorksheetDetailExtraInfoFieldsResult>
</GetWorksheetDetailExtraInfoFieldsResponse>
</soap:Body>
</soap:Envelope>
答案 0 :(得分:0)
在给定的XML中没有名称空间冲突,并且您想做的事情很容易做到:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ws="http://webservices.whitespacews.com/">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ws:WorksheetServiceProperty">
<xsl:element name="{name()}{position()}" namespace="{namespace-uri()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
这是否明智,是另一回事。具有编号名称的兄弟姐妹很难处理。更好的做法是使用属性进行编号:
<xsl:template match="ws:WorksheetServiceProperty">
<xsl:copy>
<xsl:attribute name="number">
<xsl:value-of select="position()"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>