xsl-list
[Top] [All Lists]

Re: [xsl] Extracting elements by parent

2008-03-26 07:44:13
Joe Tseng schrieb:
[...]
What I want to achieve is 1) while looping through the batches print out
all the associated elements and attributes of a batch 2) within a batch
loop through the tests and print out all the associated parameters and
associated elements and attributes of a test. [...]

If you want plain text output, you may take the following as a starting
point and then tailor it to suit your needs.

<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:output method="text"/>

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

  <xsl:template match="batch">
    <xsl:value-of select="concat('### This is batch: ', @id)"/>
    <xsl:text>&#10;</xsl:text>
    <!-- newline; for Windows, use &#13;&#10; -->
    <xsl:apply-templates select="@* | description" mode="txt"/>
    <xsl:text>&#10;</xsl:text>
    <xsl:for-each select="tests/test">
      <xsl:apply-templates select="."/>
      <xsl:text>&#10;</xsl:text>
    </xsl:for-each>
    <xsl:text>&#10;</xsl:text>
  </xsl:template>

  <xsl:template match="test">
    <xsl:value-of select="concat('--- This is test ', @id)"/>
    <xsl:text>&#10;</xsl:text>
    <xsl:apply-templates select="@* | description" mode="txt"/>
    <xsl:for-each select="params/p">
      <xsl:apply-templates select="@* | ." mode="txt"/>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="@*|*" mode="txt">
    <xsl:value-of select="concat( name(), ' : ', . , '&#10;' )"/>
  </xsl:template>

</xsl:transform>

Michael

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>