Problem changing attributes into elements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • heitikimairim
    New Member
    • Apr 2010
    • 2

    Problem changing attributes into elements

    Hi all,
    I need to design an XSL to convert this xml:
    Code:
    <Fields>
    <Field Name="DebitCredit" Type="invoicecredit">Debit Factuur</Field>
    </Fields>
    into:
    Code:
    <Fields>
    <DebitCredit>Debit Factuur</DebitCredit>
    </Fields>
    The xsl needs to be imported into an application, which is where my problem starts. I have the following xsl (which works) but for some reason (maybe the XPath being used? could be 1.0, not sure) the application doesn't accept it, so I need something without the variables (I think)
    Code:
    <xsl:template match="Fields/Field">
      <xsl:variable name="naam" select="(@Name)"></xsl:variable>
      <xsl:element name="{$naam}">
        <xsl:value-of select="."/>  
      </xsl:element>
    </xsl:template>
    Can somebody help me please?
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Remove the parentheses from your variable declaration
    <xsl:variable name="naam" select="@Name"/>

    You could also go:
    <xsl:element name="{@Name}">

    thus negating the need for a variable.

    Comment

    • heitikimairim
      New Member
      • Apr 2010
      • 2

      #3
      When I remove the parenthesis, I get a message 'is not a qname'?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        there is nothing you can do about that in the XSL, you have to change your XML accordingly (QName)

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

          #5
          ? Where are you removing the parentheses from? Post your updated code please.

          Comment

          Working...