0

这是我的 XML:

    <?xml version="1.0" encoding="UTF-8" ?>
<RequestValuesResponse xmlns="http://www.camstar.com/WebService/WSShopFloor">
   <RequestValuesResult>true</RequestValuesResult>
   <responseServiceData q3:type="LotModifyAttrs" xmlns:q3="http://www.camstar.com/WebService/DataTypes">
      <CompletionMsg xmlns="http://www.camstar.com/WebService/DataTypes">Update completed successfully</CompletionMsg>
      <SelectionContainer xmlns="http://www.camstar.com/WebService/DataTypes">
         <__name>5454545</__name>
         <__level>
            <__name>LOT</__name>
         </__level>
         <__Id>4802378000000610</__Id>
      </SelectionContainer>
      <ServiceAttrsDetailsSelection xmlns="http://www.camstar.com/WebService/DataTypes">
         <__listItem type="ServiceAttrsDetails">
            <__parent>
               <__Id>4806490000000018</__Id>
            </__parent>
            <__Id>4805ad00000001c5</__Id>
            <AttributeName>AllowLotSchedule</AttributeName>
            <AttributeValue>True</AttributeValue>
         </__listItem>
         <__listItem type="ServiceAttrsDetails">
            <__parent>
               <__Id>4806490000000018</__Id>
            </__parent>
            <__Id>4805ad00000001c9</__Id>
            <AttributeName>AssemblyCountry</AttributeName>
            <AttributeValue/>
         </__listItem>
      </ServiceAttrsDetailsSelection>
   </responseServiceData>
   <resultStatus type="q1:ResultStatus" xmlns:q1="http://www.camstar.com/WebService/DataTypes">
      <Message xmlns="http://www.camstar.com/WebService/DataTypes">Update completed successfully</Message>
      <IsError xmlns="http://www.camstar.com/WebService/DataTypes">false</IsError>
   </resultStatus>
</RequestValuesResponse>

我的 XSL 如下所示:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                xmlns:ns2="http://www.camstar.com/WebService/WSShopFloor"
                xmlns:q3="http://www.camstar.com/WebService/DataTypes"
                exclude-result-prefixes="q3 xsi xsl xsd wsdl ns2">
<xsl:output omit-xml-declaration="yes"/>
  <xsl:template match="/">
    <AttributeDetailsCollection>
      <xsl:copy-of select="/ns2:RequestValuesResponse/ns2:responseServiceData/q3:ServiceAttrsDetailsSelection">
        <?oracle-xsl-mapper-position ServiceAttrsDetailsSelection?>
      </xsl:copy-of>
    </AttributeDetailsCollection>
  </xsl:template>
</xsl:stylesheet>

xsl的输出:

<?xml version = '1.0' encoding = 'UTF-8'?>
<AttributeDetailsCollection>
   <ServiceAttrsDetailsSelection xmlns="http://www.camstar.com/WebService/DataTypes" xmlns:q3="http://www.camstar.com/WebService/DataTypes">
         <__listItem type="ServiceAttrsDetails">
            <__parent>
               <__Id>4806490000000018</__Id>
            </__parent>
            <__Id>4805ad00000001c5</__Id>
            <AttributeName>AllowLotSchedule</AttributeName>
            <AttributeValue>True</AttributeValue>
         </__listItem>
         <__listItem type="ServiceAttrsDetails">
            <__parent>
               <__Id>4806490000000018</__Id>
            </__parent>
            <__Id>4805ad00000001c9</__Id>
            <AttributeName>AssemblyCountry</AttributeName>
            <AttributeValue/>
         </__listItem>
      </ServiceAttrsDetailsSelection>
</AttributeDetailsCollection>

注意输出中的行:

<ServiceAttrsDetailsSelection xmlns="http://www.camstar.com/WebService/DataTypes" xmlns:q3="http://www.camstar.com/WebService/DataTypes">

最好我希望删除两个命名空间声明,所以它应该是:

<ServiceAttrsDetailsSelection>

但至少它应该看起来像:

<ServiceAttrsDetailsSelection xmlns:q3="http://www.camstar.com/WebService/DataTypes">

我可以处理带前缀的命名空间。

4

1 回答 1

0

copy-of如果要更改命名空间,则不能使用。因此,通过剥离命名空间的模板推送您的元素:

  <xsl:template match="/">
    <AttributeDetailsCollection>
      <xsl:apply-templates select="/ns2:RequestValuesResponse/ns2:responseServiceData/q3:ServiceAttrsDetailsSelection">
    </AttributeDetailsCollection>
  </xsl:template>

<xsl:template match="ns2:*">
  <xsl:element name="{local-name()}">
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>
于 2013-07-31T17:29:18.787 回答