Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Iteration

From: Mike Brown <mike@-------->
To:
Date: 7/1/2000 9:44:00 AM
> 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


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent