Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 22nd, 2015, 07:43 AM
Registered User
 
Join Date: Jul 2015
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default preceding-sibling

Hi,

I have a problem with numbering through XSLT. My first approach, something like
Code:
<xsl:number level="any" format="1. " from="nliste[@reset='reset']" count="nliste"/>
failed as the different XSLT-interpreters behave differently on the first element. E.g., Xalan starts with 1, Xerces with nothing and whatever is used by Firefox with 0 oder vice versa. As it was only used to create FO code for Apache FOP, I could live with a custom FOP version on our server.

Now, I create HTML from the very same XML to be presented on the clients browsers, so I have to figure out a different way for numbered lists without changing the DTD.

I came up with
Code:
<xsl:value-of select="count(preceding-sibling::nliste)+1"/>
what works perfectly on Firefox and IE (it stops counting on a preceding sibling that's not the element in focus. However, Epiphany on a Raspberry Pi failed miserably by numbering all nliste-siblings, no matter if there is a different element between them.

My question: What's right, what's wrong, and what is a good approach on numbering. I know my nliste element was never a good idea, but it's quite late to change that.

TIA

Thomas

Edit: Now that I've written it down, I see I'm in error. All parsers count all siblings. Sorry :-(.

Last edited by thradtke; July 22nd, 2015 at 08:15 AM..
 
Old July 22nd, 2015, 09:16 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

During the development of XSLT 2.0 the working group found that there were many discrepancies in the way that XSLT 1.0 processors interpreted the 1.0 spec of xsl:number, especially in edge cases involving the "from" and "count" attributes. The XSLT 2.0 spec was therefore rewritten to be much more precise. The 2.0 spec represents the WG's view of what constitutes "correct" behaviour, but 1.0 processors can't be expected to take that interpretation. If you want interoperability, you have to avoid the edge cases. In many cases it's simpler anyway to use constructs like count(preceding-sibling::x).
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
thradtke (July 22nd, 2015)
 
Old July 22nd, 2015, 09:42 AM
Registered User
 
Join Date: Jul 2015
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mhkay View Post
If you want interoperability, you have to avoid the edge cases. In many cases it's simpler anyway to use constructs like count(preceding-sibling::x).
Yes, but my problem is that I cannot (easily) have different sets of lists like in e.g.
Code:
<doc>
  <nliste reset='reset'>first entry of the first list</nliste>
  <nliste>second entry of the first list</nliste>
  <absatz>This is a paragraph</absatz>
  <nliste reset='reset'>first entry of the second list</nliste>
  <nliste>second entry of the second list</nliste>
</doc>
which should translate to
Code:
  1. first entry of the first list
  2. second entry of the first list

This is a paragraph

  1. first entry of the second list
  2. second entry of the second list
TBH, I don't know how to proceed. I'd appreciate any help, especially a pointer to a good tutorial on these matters.
 
Old July 23rd, 2015, 04:43 AM
Registered User
 
Join Date: Jul 2015
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Solved it by generating html on the server and using xsl:number. Seems to be the best solution.

Very sad browsers do not adopt the latest technologies





Similar Threads
Thread Thread Starter Forum Replies Last Post
If preceding-sibling question XadRav XSLT 4 January 28th, 2011 04:10 AM
Want to Pull multiple following-sibling data to preceding-sibling element sameer_kadam XSLT 4 May 9th, 2009 08:07 AM
Preceding Sibling mphare XSLT 3 March 4th, 2009 11:04 AM
Using preceding-sibling mcanne98 Infopath 0 September 11th, 2008 11:09 PM
preceding-sibling jonesyp XSLT 2 November 22nd, 2005 12:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.