copying all attributes in XSLT

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • R

    copying all attributes in XSLT

    Hello everybody.

    I've got my XML file with 'field' node .

    Field is transformed with XSLT into paragraph tag in XHTML.

    But. A programmer can add various attributes to <field> node, eg.
    someone can add 'onclick', 'onmouseover', 'style', 'class', 'align'
    attributes and so on. I want to copy all the attributes from <field>
    to <p>.
    But field has also two attributes that can't be copied: 'id' and
    'number'.

    And the final question ;-):
    How to copy all the attributes without 'id' and 'number' ones?

    thanks in advance for any help
    best regards
    R
  • Joris Gillis

    #2
    Re: copying all attributes in XSLT

    Tempore 18:37:57, die Thursday 10 March 2005 AD, hinc in foro {comp.text.xml} scripsit R <ruthless@poczt a.onet.pl>:
    [color=blue]
    > And the final question ;-):
    > How to copy all the attributes without 'id' and 'number' ones?[/color]
    <xsl:copy-of select="@*[not(self::id or self::number)]"/>

    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
    "Quot capita, tot sententiae" - Terentius , Phormio 454

    Comment

    • Martin Honnen

      #3
      Re: copying all attributes in XSLT



      R wrote:

      [color=blue]
      > How to copy all the attributes without 'id' and 'number' ones?[/color]

      <xsl:template match="field">
      <p>
      <xsl:copy-of select="@*[local-name() != 'id' and local-name() !=
      'number']" />
      <xsl:apply-templates />
      </p>
      </xsl:template>

      --

      Martin Honnen

      Comment

      • David Carlisle

        #4
        Re: copying all attributes in XSLT


        "Joris Gillis" <roac@pandora.b e> writes:
        [color=blue]
        > Tempore 18:37:57, die Thursday 10 March 2005 AD, hinc in foro {comp.text.xml} scripsit R <ruthless@poczt a.onet.pl>:
        >[color=green]
        > > And the final question ;-):
        > > How to copy all the attributes without 'id' and 'number' ones?[/color]
        > <xsl:copy-of select="@*[not(self::id or self::number)]"/>
        >[/color]


        You have to use name()!='id' rather than not(self::id) as self::id
        selects elements not attributes.

        David

        Comment

        • Joris Gillis

          #5
          Re: copying all attributes in XSLT

          Tempore 23:15:34, die Thursday 10 March 2005 AD, hinc in foro {comp.text.xml} scripsit David Carlisle <davidc@nag.co. uk>:
          [color=blue][color=green][color=darkred]
          >> > And the final question ;-):
          >> > How to copy all the attributes without 'id' and 'number' ones?[/color]
          >> <xsl:copy-of select="@*[not(self::id or self::number)]"/>
          >>[/color]
          >
          > You have to use name()!='id' rather than not(self::id) as self::id
          > selects elements not attributes.[/color]

          If that is true - and I do not doubt that you're right - then I've been posting non-working code for months:-(
          Yet another bug in my XSLT processor (it select attributes and element in the 'self' axis), I should really consider moving to another...

          Thanks for pointing it out.

          regards,
          --
          Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
          Gaudiam omnibus traderat W3C, nec vana fides

          Comment

          Working...