XSLT Transformation - dynamic element names

前端 未结 2 2090
梦毁少年i
梦毁少年i 2021-01-05 11:54

Source Input



        
相关标签:
2条回答
  • 2021-01-05 12:31

    Something along these lines, if I understand you correctly:

    <xsl:element name="name()">
     <xsl:value-of select="./text()" />
    </xsl:element>
    
    0 讨论(0)
  • 2021-01-05 12:37

    This XSL Stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output indent="yes"/>
      <xsl:strip-space elements="*"/>
    
      <xsl:template match="node()|@*">
        <xsl:copy>
          <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="Field">
        <xsl:element name="{@Name}">
          <xsl:value-of select="@Value"/>
        </xsl:element>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Applied to well-formed input:

    <SiebelMessage MessageId="1-18J35" IntObjectName="XRX R5 Letter Instance"  MessageType="Integration Object" IntObjectFormat="Siebel Hierarchical">
      <LetterInstance  Id="1-1RUYIF" Language="ENU" TemplateType="SA">
        <Field  Value="CO Last Name"  Datatype="String" Name="ContractingOfficerLastName"/>
      </LetterInstance>
    </SiebelMessage>
    

    Produces:

    <SiebelMessage MessageId="1-18J35" IntObjectName="XRX R5 Letter Instance" MessageType="Integration Object" IntObjectFormat="Siebel Hierarchical">
       <LetterInstance Id="1-1RUYIF" Language="ENU" TemplateType="SA">
          <ContractingOfficerLastName>CO Last Name</ContractingOfficerLastName>
       </LetterInstance>
    </SiebelMessage>
    

    I'm not sure where <PONumber> is supposed to be generated from.

    0 讨论(0)
提交回复
热议问题