Scott,
When I use this XML:
<TABLE>
<DPROW>
<OBJECT>1</OBJECT>
<TABLE>
<DPROW>
<OBJECT>2</OBJECT>
<OBJECT>3</OBJECT>
<OBJECT>4</OBJECT>
<TABLE>
<DPROW>
<OBJECT>5</OBJECT>
<OBJECT>6</OBJECT>
<OBJECT>7</OBJECT>
<OBJECT>8</OBJECT>
<OBJECT>9</OBJECT>
</DPROW>
</TABLE>
</DPROW>
</TABLE>
<TABLE>
<DPROW>
<OBJECT>10</OBJECT>
<OBJECT>11</OBJECT>
<OBJECT>12</OBJECT>
<OBJECT>13</OBJECT>
<TABLE>
<DPROW>
<OBJECT>14</OBJECT>
<OBJECT>15</OBJECT>
<OBJECT>16</OBJECT>
<OBJECT>17</OBJECT>
<OBJECT>18</OBJECT>
<OBJECT>19</OBJECT>
</DPROW>
</TABLE>
<TABLE>
<DPROW>
<OBJECT>20</OBJECT>
<OBJECT>21</OBJECT>
<OBJECT>22</OBJECT>
<OBJECT>23</OBJECT>
<OBJECT>24</OBJECT>
<OBJECT>25</OBJECT>
<OBJECT>26</OBJECT>
<OBJECT>27</OBJECT>
<OBJECT>28</OBJECT>
</DPROW>
</TABLE>
</DPROW>
</TABLE>
</DPROW>
</TABLE>
and either of the templates I provided...
I get 1 3 5 4 6 9 as output.
I think the problem is that we did not have an agreement of the tree
traversal order. My algorithm is a preorder traversal, and you may
want inorder or postorder. Look at how I have the objects numbered and
change it to include the order you want. This is where we may have to
use recursion.
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
scott
gabelhart
Sent: Wednesday, February 04, 2004 5:30 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] XPath statement for traversing a nested node
structure
Kenny Akridge wrote:
If you are looking for a simple count of each object within a node(not
a
sum of objects that includes the table subnode), then both of these
will
work:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="//TABLE">
<xsl:value-of select="concat(count(DPROW/OBJECT),
' ')"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="//TABLE"/>
</xsl:template>
<xsl:template match="TABLE">
<xsl:apply-templates select="DPROW"/>
</xsl:template>
<xsl:template match="DPROW">
<xsl:value-of select="concat(count(OBJECT), ' ')"/>
</xsl:template>
</xsl:stylesheet>
However, if you need the sum then you will need to use some
recurision(off hand this is what I am thinking).
I think your problem with DPROW/OBJECT is that you are getting a count
based on the first table context.
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
scott
gabelhart
Sent: Wednesday, February 04, 2004 2:40 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] XPath statement for traversing a nested node structure
I need some assistance with traversing a nested xml input file
structure.
I need to determine between the begining of one nested structure and
another the number of occurances of a particular element.
Example:
<TABLE><DPROW><OBJECT></OBJECT></DPROW></TABLE> would yield an
occurance
of one OBJECT element using the XPath statement DPROW/OBJECT.
The above XPath statement falls apart though when I introduce nested
structures.
<TABLE><DPROW><OBJECT></OBJECT><TABLE><DPROW><OBJECT></OBJECT><OBJECT><
/
OBJECT></DPROW></TABLE></DPROW></TABLE>
Inner most TABLE element has two OBJECT elements and the outer TABLE
element would yield one OBJECT element.
What is a valid XPath statement need for traversing the nested xml
structure above?
Any help would be greatly appreciated.
- Scott
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Kenny running your second xsl example gets me closer; but still run into
error after the third nested table structure.
Here is the output
1Â 2Â 15Â 14Â 10Â 6Â 13Â 14Â 4Â 16Â 1Â 1Â 1Â 1Â 1Â 1Â 1Â 1Â 12Â 10Â 10Â
10Â 10Â 10Â 10Â 10Â 10Â 10Â 9Â 10Â 10Â 10Â 10Â 10Â 10Â 10Â 10Â 10Â
Based upon my xml structure the 14^A should only be returning 3 ^A.
Also can you include a recursive example. I have never used recursion in
my transforms before.
Thanks in advance.
- Scott
- Scott
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list