 |
| 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
|
|
|
|

February 13th, 2009, 09:57 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2007
Posts: 115
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Xslt defining the third object from current
Hi, I don't know xml.
The stylesheet identifies all the objects from DB & as it reads through the DB, it checks the next object "for-each", I need to check the third object as well & define within var being "nextNode3"
I need to specify in the stylesheet to look for the next column â so that I can insert the xml.
This is the code that checks/defines for current & next, with the next being "nextNode"
<xsl:for-each select="Activity/ObjectGroup[@type='default']/Object">
<xsl:sort select="@index" data-type="number" />
<xsl:variable name="index" select="@index" />
<xsl:variable name="nextNode" select="../Object[ @index > $index ][1]" />
<xsl:variable name="nextCol" select="$nextNode/@columnNo" />
<xsl:variable name="vis" select="string(Attributes/Attribute[ @name='visible'])" />
<xsl:variable name="visNextCol" select="string($nextNode/Attributes/Attribute[ @name='visible'])" />
nextNode specifies the next object & nextCol specifies the next objects column
Now I just need to specify the 3rd object
This is what i tried - unsuccessful
<xsl:variable name="nextNode3" select="../Object[ @index > $index ][2]" />
<xsl:variable name="nextCol3" select="$nextNode3/@columnNo" />
<xsl:variable name="visNextCol3" select="string($nextNode3/Attributes/Attribute[ @name='visible'])" />
Please Assist, Not to sure
Regards
|
|

February 13th, 2009, 10:21 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Can you show us a sample of your XML input and then describe which nodes in the input you want to select?
Also you said you unsuccessfully tried <xsl:variable name="nextNode3" select="../Object[ @index > $index ][2]" />, how exactly does that fail? Is the position wrong? Third object in XPath would be [3] instead of [2].
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

February 13th, 2009, 10:34 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
<xsl:variable name="nextNode" select="../Object[ @index > $index ][1]" />
is going to select the first object in your unsorted input whose key is greater than the current object. That's not the same thing as selecting the next item in the sorted input.
In XSLT 2.0 you can assign a sorted sequence to a variable, and then index into the sorted sequence directly. But I would want to see a description of the problem before advising further.
There's no direct way of doing this in XSLT 1.0, but as is often the way you can do it if your processor offers the xx:node-set() extension function.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

February 16th, 2009, 03:15 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2007
Posts: 115
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Hi, Thank You for the assist, unfortunately not winning.
I'm only editing an existing xslt file and have no experience in xml.
The current file allows for 2 objects to be next to one another on one row when object2 column no = 2.
I want to add a third object to the row when column no = 3, but i can't determine the 3rd object, on one row = object1, object2, object3
This is the code of the original xslt file, code in bold is what I added.
<?xmlversion="1.0"?>
<xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="1.0"xmlns:asp="remove"xmlns:igchart="remove"xmlns:igsch="remove"xmlns:igtxt="remove">
<xsl:outputomit-xml-declaration = "yes" />
<xsl:templatematch="/">
<xsl:for-eachselect="Activity/ObjectGroup[@type='default']/Object">
<xsl:sortselect="@index"data-type="number" />
<xsl:variablename="index"select="@index" />
<xsl:variablename="nextNode"select="../Object[ @index > $index ][1]" />
<xsl:variablename="nextCol"select="$nextNode/@columnNo" />
<xsl:variablename="nextNode3"select="../Object[ @index > $index ][3]" />
<xsl:variablename="nextCol3"select="$nextNode3/@columnNo" />
<xsl:variablename="visNextCol3"select="string($nextNode3/Attributes/Attribute[ @name='visible'])" />
<xsl:variablename="vis"select="string(Attributes/Attribute[ @name='visible'])" />
<xsl:variablename="visNextCol"select="string($nextNode/Attributes/Attribute[ @name='visible'])" />
<xsl:iftest="($vis != 'False') or ($nextCol = '2' and ($vis != 'False' or $visNextCol != 'False')) or ($nextCol3 = '3')">
<xsl:iftest="(@columnNo != '2')">
<tr>
<xsl:iftest="($nextCol = '2') and $visNextCol != 'False'">
<tr>
</xsl:if>
<xsl:iftest="($nextCol3 = '3') and $visNextCol3 != 'False'">
<tr>
</xsl:if>
</xsl:if>
</xsl:if>
It gives me an error, the third object is already used by another control
Please help, Regards
Last edited by ismailc; February 16th, 2009 at 03:28 AM..
|
|

February 16th, 2009, 05:15 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I've no idea what the error message means, there is no such thing as a "control" in XSLT. What processor are you using, and how are you running it?
However, you haven't grasped what I told you in the previous response, and there's really no point in saying the same thing again. Editing code in a programming language you don't understand is a dangerous thing to do, and I would advise you to read up about the concepts of the language before attempting it. You're unlikely to understand the answers to questions on this forum unless you first understand the basic concepts of the language.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
 |