This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Copying node but changing attributes




well, you've done 99% of the work, the only thing to
do is fill in       <!-- DO SOMETHING WITH ATTR -->
(and take out xsl:copy)
but hard to say as you haven't said how you want to change the
attribute.

For example

<xsl:template match="node">
  <xsl:copy>
    <xsl:copy-of"@*[not(name()='x' or name()='y')]">
     <xsl:attribute name="xxx">
        <xsl:value-of select="@y"/>
     </xsl:attribute>
     <xsl:attribute name="yyy">
        I was here
     </xsl:attribute>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>


copies any attribute not called x or y, makes a new attribute xxx with
the data from the old y attribute, makes a new attribute yyy
and doesn't use the old x attribute at all.

or perhaps

<xsl:template match="node">
  <xsl:copy>
    <xsl:for-each select="@*">
      <xsl:attribute name="new-{name()}">
      <xsl:text>modified from </xsl:text>
      <xsl:value-of select="."/>
     </xsl:attribute>
    </xsl:for-each>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>


which changes

<node a="1" b="2">

to

<node new-a="modified from 1" new-b="modified from 2">

or at least I hope it does, haven't checked:-)

David


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]