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: Iteration


> I'm trying to use XSL to parse XML to PROLOG, and cannot find
> a means of iterating over every element.

<xsl:template match="/">
  <xsl:apply-templates select="//*"/>
</xsl:template>

<xsl:template match="*">
  <!-- stuff to do for each element here -->
</xsl:template>

or, since //foo is inefficient,

<xsl:template match="/">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="*">
  <!-- stuff to do for each element here -->
  <!-- when done, go process this element's child elements -->
  <xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="text()|comment()|processing-instruction|@*"/>

> Is it possible, say,
> to use XSL without additional ECMA/VB-/J-/JavaScript scripting
> to display every element and it's attributes?

Replace <!-- stuff to do... --> with the appropriate code, depending on
the output you want. Example:

<xsl:value-of select="concat(name(),': ',text(),'&#xA;')"/>
<xsl:for-each select="@*">
  <xsl:value-of select="concat('   ',name(),': ',text(),'&#xA;')"/>
</xsl:for-each>

would give you something like:

element1: text1
  attribute1a: value1a
  attribute1b: value1b
element2: text2
  attribute2a: value2a
element3: text3

etc.

   - Mike
____________________________________________________________________
Mike J. Brown, software engineer at         My XML/XSL resources:
webb.net in Denver, Colorado, USA           http://www.skew.org/xml/


 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]