Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to iterate through a node's attributes

Status
Not open for further replies.

TonyMarston

Programmer
Dec 8, 1999
20
0
0
GB
I have a stylesheet with the following code:
Code:
  <xsl:for-each select="//structure/table/column">
    <col>
      <xsl:if test="@width">
        <xsl:attribute name="width" ><xsl:value-of select="@width" /></xsl:attribute>
      </xsl:if>
      <xsl:if test="@class">
        <xsl:attribute name="class" ><xsl:value-of select="@class" /></xsl:attribute>
      </xsl:if>
      <xsl:if test="@align">
        <xsl:attribute name="align" ><xsl:value-of select="@align" /></xsl:attribute>
      </xsl:if>
      <xsl:if test="@valign">
        <xsl:attribute name="valign" ><xsl:value-of select="@valign" /></xsl:attribute>
      </xsl:if>
      <xsl:if test="@char">
        <xsl:attribute name="char" ><xsl:value-of select="@char" /></xsl:attribute>
      </xsl:if>
      <xsl:if test="@style">
        <xsl:attribute name="style" ><xsl:value-of select="@style" /></xsl:attribute>
      </xsl:if>
    </col>
  </xsl:for-each>
As you can see for each 'column' node it examines and processes each attribute by name. Is there a way to process each attribute with an <xsl:for-each > and to obtain each attribute's name and value without having it hard-coded?
 
Something like this?
[tt]
<xsl:for-each select="//structure/table/column">
<col>
<xsl:copy-of select="@*" />
</col>
</xsl:for-each>
[/tt]
 
If you don't mean every attribute, then it is something like this.
[tt]
<xsl:for-each select="//structure/table/column">
<col>
<xsl:for-each select="@width|@class|@align|@valign|@char|@style">
<xsl:copy-of select="." />
</xsl:for-each>
</col>
</xsl:for-each>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top