This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Iteration
- To: xsl-list at mulberrytech dot com
- Subject: Re: Iteration
- From: Mike Brown <mike at skew dot org>
- Date: Sat, 1 Jul 2000 15:44:01 -0600 (MDT)
- Reply-To: xsl-list at mulberrytech dot com
> 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(),'
')"/>
<xsl:for-each select="@*">
<xsl:value-of select="concat(' ',name(),': ',text(),'
')"/>
</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