[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSL counting node by inheritable attribute

Subject: XSL counting node by inheritable attribute
From: paavali muurahainen <paavalimuurahainen@xxxxxxxxx>
Date: Wed, 17 Nov 2010 13:01:09 +0800
 XSL counting node by inheritable attribute
Hello,

I'm creating an XSL transformation to show my XML file in a web
browser. I want to view the data, and then finally create a matrix
that calculates number of nodes matching certain criteria. The problem
is, that the criteria can be inherited. I'm using XSLT 1.0 due to
browsers not often supporting anything else.

The XML document I have looks like this (the static items):
<root>
  <level1 feature="XXX">
     <level2>
        <level3/>
     </level2>
  </level1>
</root>

Now, all level-nodes can have an attribute called type. The attribute
is inherited and can be overridden, which is the root cause of my
current problem when I want to create the matrix. The matrix, ie. a
table, would contain columns for all different types found, and rows
for features, and the value of each cell would be the number of level3
items that match the type and feature of that particular cell.

After giving this a long thought I've come up with two solutions:
1) Loop over the list of features, and inside it the list of types,
and create a very complex math operation counting the items
2) Somehow set the attribute type for each level3 item so that I could
just write <xsl:value-of
select="count(level1[@feature='XXX']/level2/level3[@type='YYY'])"/>

The option 1 is something I know how to do but don't want to because
of the number of different scenarios that should be included and
excluded.

The XSL structure now goes like this:
<xsl:stylesheet>
  <xsl:template match="/">
    <here some general HTML output>
    <xsl:apply-templates />
    <xsl:call-template name="matrix"/>
  </xsl:template>

  <xsl:template match="level1">
    <again, HTML>
    <xsl:for-each select="level2">
      <xsl:apply-templates select="."/>
    </xsl:for-each>
 </xsl:template>

  <xsl:template match="level2">
    <again, HTML>
    <xsl:for-each select="level3">
      <xsl:apply-templates select="."/>
    </xsl:for-each>
 </xsl:template>

  <xsl:template match="level3">
    <again, HTML>
 </xsl:template>

 <xsl:template name="matrix">
   <here I want to create the matrix>
 </xsl:template>
</xsl:stylesheet>

How could I achieve option number 2, ie. setting the type attribute
for all level3 items?

BR,
Paavali

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.