Help with transformation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zoom007
    New Member
    • Jun 2007
    • 6

    Help with transformation

    I'll be grateful if anyone would help me with this problem.
    I am trying to construct a stylesheet to transform one xml to another. for example how do I transform:

    <root>
    <m1>sassy</m1>
    <m2>spiffy</m2>
    <sp1>suddenly </sp1>
    </root>

    To:

    <mls>
    <hd>sassy</hd>
    <hd2>spiffy</hd2>
    </mls>

    Thanks!!!
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by zoom007
    I'll be grateful if anyone would help me with this problem.
    I am trying to construct a stylesheet to transform one xml to another. for example how do I transform:
    [HTML]
    <root>
    <m1>sassy</m1>
    <m2>spiffy</m2>
    <sp1>suddenly </sp1>
    </root>

    To:

    <mls>
    <hd>sassy</hd>
    <hd2>spiffy</hd2>
    </mls>
    [/HTML]
    Thanks!!!
    Hello, zoom007!

    Please take a look here, see if anything springs your memory:



    Continue to stay tuned if not helpful, will try to get you caught up...

    Good luck and welcome!

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      Create templates based on what each element is mapped to, and then use apply-templates for the rest:
      Code:
      <xsl:template match="root">
      <mls><xsl:apply-templates/></mls>
      </xsl:template>
      <xsl:template match="m1">
      <hd><xsl:apply-templates/></hd>
      </xsl:template>
      <xsl:template match="m2">
      <hd2><xsl:apply-templates/></hd2>
      </xsl:template>
      <xsl:template match="sp1"/><!-- remove element -->

      Comment

      Working...