XSLT映射-在元素内部使用value-Of

时间:2019-04-09 01:52:03

标签: xslt

我在下面输入了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中“ Object”的值:

<?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标签的值

感谢所有帮助

1 个答案:

答案 0 :(得分: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>