Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How to build a table?

From: Ivan Peters <ivan@--.----.--->
To: NULL
Date: 6/6/2006 9:03:00 AM

anotherron wrote:
> Thanks Anthony and Ivan. Your exmples are very helpful. There is one detail 
> that I left out of my original post. (I did not realize at the time that it 
> was important.) I actually have to sort the xml data before traversing the 
> tree. Specifically the code is:
> 
> <xsl:for-each match="parent">
>  <xsl:sort  select="child"/>
>   ...
> </xsl:for-each>
> 
> The problem that I am now encountering is that position() uses the 
> document's sort order not the order specified by the sort element. Is there a 
> method that will use the sort element's order. (I assume that the sort 
> element does not actually create a new tree.) Thanks in advance.

The problem is that the for-each filter is applied befor the sort.  Move 
the position test inside the loop and it should be fine.

But... the following-sibling axis returns nodes in document order so 
tha't going to be a problem.  The only "proper" solution to this is to 
have a second loop to process the nodes in sort order and find the next 
one (could be a performance problem with large node sets).

<table>
  <xsl:variable name="parents" select="parent"/>
  <xsl:for-each select="$parents">
  <xsl:sort select="child"/>
  <xsl:if select="position() mod 2 = 1">
   <xsl:variable name="index" select="position()"/>
   <tr>
    <td>
    <xsl:apply-templates select="child"/>
    </td>
    <td>
     <xsl:for-each select="$parents">
     <xsl:sort select="child"/>
     <xsl:if select="position() = $index + 1">
      <xsl:apply-templates select="child"/>
     </xsl:if>
     </xsl:for-each>
    </td>
   </tr>
  </xsl:if>
  </xsl:for-each>
</table>

Or, you could use a node-set extension function (if your processor has 
one) to seperate your sorted nodes from the source document.

Or, you go back to plan A and use this to insert your TR tags:

<xsl:text disable-output-escaping="yes">
<![CDATA[<tr>]]>
</xsl:text>

The well-formedness rules of XSL ensure that your output is well formed. 
  This technique allows you to break those rules which could result in 
invalid output if you are not careful.  So don't go crazy with it.

Ivan


transparent
Print
Mail
Like It
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