xsl-list
[Top] [All Lists]

RE: Grouping and transforming XML elements

2003-06-10 01:11:55
Hi,

type(1) subtype(2): A, B, C. type(2) subtype(3): ZZ, WW. type(3): JJ.
type(1) subtype(2): AA, BB.

That is, each <stuff> is to be on a line of its own. Some 
sample code would 
be fantastic.

  <xsl:output method="text"/>
  <xsl:template match="/">
    <xsl:for-each select="doc/stuff">
      <xsl:if test="not(position() = 1)">
        <xsl:text>&#xA;</xsl:text>
      </xsl:if>
      <xsl:for-each select="*[not(@type = preceding-sibling::*[1]/@type)]">
        <xsl:text/>type(<xsl:value-of select="@type"/>) <xsl:text/>
        <xsl:for-each select="../*[(_at_)type = current()/@type and 
not(@subtype = preceding-sibling::*[1]/@subtype)]">
          <xsl:choose>
            <xsl:when test="@subtype">
              <xsl:text/>subtype(<xsl:value-of select="@subtype"/>): <xsl:text/>
              <xsl:for-each select="../*[(_at_)type = current()/@type and 
@subtype = current()/@subtype]">
                <xsl:if test="not(position() = 1)">, </xsl:if>
                <xsl:value-of select="."/>
              </xsl:for-each>
              <xsl:text>. </xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:for-each select="../*[(_at_)type = current()/@type]">
                <xsl:if test="not(position() = 1)">, </xsl:if>
                <xsl:value-of select="."/>
              </xsl:for-each>
              <xsl:text>. </xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>

Use keys if you need more speed.

Cheers,

Jarno - Hocico: Poltergeist

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



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