0

我有以下输入 XML:

<?xml version="1.0" encoding="UTF-8"?>
<Input>
   <MESSAGE>Success</MESSAGE>
   <OBJECT>Task</OBJECT>
</Input>

我需要将其转换为以下内容:

<ExecuteMultipleOperations xmlns="http://www.MySoftware.com">
   <Operations>
      <Operation>
         <Action>UpdateOrCreate</Action>
         <Object>
            <Object xmlns:p1="http://www.w3.org/2001/XMLSchema-instance" p1:type="Task">
               <Name>Success</Name>
            </Object>
         </Object>
      </Operation>
      <OneTransaction>false</OneTransaction>
      <ContinueOnError>true</ContinueOnError>
   </Operations>
</ExecuteMultipleOperations>

下面是 XSLT 正在使用但无法在 p1:type 中获取“对象”的值:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="/">
      <ExecuteMultipleOperations xmlns="http://www.MySoftware.com">
         <Operations>
            <Operation>
               <Action>UpdateOrCreate</Action>
               <Object>
                  <Object p1:type="//OBJECT" xmlns:p1="http://www.w3.org/2001/XMLSchema-instance">
                     <Name>
                        <xsl:value-of select="//MESSAGE"/>
                     </Name>
                    </Object>
               </Object>
            </Operation>
            <OneTransaction>false</OneTransaction>
            <ContinueOnError>true</ContinueOnError>
         </Operations>
      </ExecuteMultipleOperations>
   </xsl:template>
</xsl:stylesheet>

您能否告知我如何在 p1:type 中获取 //OBJECT 标记的值

感谢所有的帮助

4

1 回答 1

0

请使用此代码

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="1.0">
    <xsl:output method="xml" omit-xml-declaration="no"/>
    <xsl:template match="Input">
        <ExecuteMultipleOperations xmlns="http://www.MySoftware.com">
            <Operations>
                <Operation>
                    <Action>UpdateOrCreate</Action>
                    <Object>
                        <Object xmlns:p1="http://www.w3.org/2001/XMLSchema-instance" p1:type="{OBJECT}">
                            <Name><xsl:value-of select="MESSAGE"/></Name>
                        </Object>
                    </Object>
                </Operation>
                <OneTransaction>false</OneTransaction>
                <ContinueOnError>true</ContinueOnError>
            </Operations>
        </ExecuteMultipleOperations>
    </xsl:template>
</xsl:stylesheet>
于 2019-04-09T02:47:27.720 回答