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

May 23rd, 2006, 02:31 PM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
xsl:key doesnt work
<xsl:key name="b" match="Field/@label" use="."/>
<xsl:key name="c" match="Field/@type" use="."/>
....
<xsl:template name="generate-top-elements">
<tr>
<xsl:for-each select="//@label[generate-id(.)=generate-id(key('b',.)[1])]">
<td><xsl:value-of select="."/></td>
</xsl:for-each>
</tr>
....
<xsl:for-each select="//@type[generate-id(.)=generate-id(key('c',.)[1])]">
<td><xsl:value-of select="."/>
....
</xsl:template>
and an xml
<Fields>
<Field type="Separator" title="Account Setup" start="yes" pos="top"/>
<Field type="TextBox" label="First Name"></Field>
<Field type="TextBox" label="Middle Name"></Field>
<Field type="TextBox" label="Last Name"></Field>
<Field type="End"/>
<Field type="Separator" title="Investments" pos="level"/>
<Field type="DropDownList" label="Primary Service Type"></Field>
...
and the output
<table>
<tr>
<td>Account Setup</td>
</tr>
</table>
<table>
<tr>
<td>First Name</td>
<td>Middle Name</td>
<td>Last Name</td>
<td>Primary Service Type</td>
<td>Traits</td>
</tr>
<tr>
<td>First Name</td>
<td>Middle Name</td>
<td>Last Name</td>
<td>Primary Service Type</td>
<td>Traits</td>
</tr>
<tr>
<td>First Name</td>
<td>Middle Name</td>
<td>Last Name</td>
<td>Primary Service Type</td>
<td>Traits</td>
</tr>
</table>
<table>
<tr>
<td>Investments</td>
</tr>
</table>
<table>
<tr>
<td>Primary Service Type</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Traits</td>
<td></td>
<td></td>
</tr>
</table>
but should be
<table>
<tr>
<td>Account Setup</td>
</tr>
</table>
<table>
<tr>
<td>First Name</td>
<td>Middle Name</td>
<td>Last Name</td>
</tr>
<tr>
<td>TextBox</td>
<td>TextBox</td>
<td>TextBox</td>
</tr>
</table>
<table>
<tr>
<td>Investments</td>
</tr>
</table>
<table>
<tr>
<td>Primary Service Type</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Traits</td>
<td></td>
<td></td>
</tr>
</table>
is there a way I could put a condition on the key? thanks
|
|

May 24th, 2006, 04:25 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
You haven't shown enough of your code to see where the problem is. And I can't see where "Traits" comes from either. Please construct a simplified example to illustrate the problem, and then show the complete code. (Sometimes this exercise helps you to find your own bug before you post it.)
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

May 24th, 2006, 06:12 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i have this code
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="remove">
<xsl:output method="html" />
<xsl:key name="b" match="Field/@label" use="." />
<xsl:key name="c" match="Field/@value" use="." />
<xsl:key name="x" match="Field/@label" use="generate-id((self::Field[@pos='top']|following-sibling::Field[@label='End'])[last()])"/>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Form/Pages/Page">
<table>
<xsl:apply-templates select="Fields" />
</table>
</xsl:template>
<xsl:template match="Fields">
<tr>
<xsl:for-each select="Field[@pos='top']">
<td>
<xsl:copy-of select="key('x',generate-id())"/>
</td>
</xsl:for-each>
</tr>
</xsl:template>
and xml
<?xml version="1.0"?>
<Form>
<Pages>
<Page>
<Fields>
<Field type="Separator" label="none" title="Accounts Setup" pos="top"/>
<Field type="TextBox" label="one" value="- 1" />
<Field type="TextBox" label="two" value="- 2" />
<Field type="TextBox" label="three" value="- 3" />
<Field type="End" label="End" />
<Field type="Separator" label="none" title="Investment" pos="top" columns="2"/>
<Field type="TextBox" label="four" value="- 4"/>
<Field type="TextBox" label="five" value="- 5"/>
<Field type="End" label="End" />
</Fields>
</Page>
</Pages>
</Form>
I need to get the nodes between the type=separator and type=End and put them in a table like this
<table>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
<tr>
<td>- 1</td>
<td>- 2</td>
<td>- 3</td>
</tr>
</table>
<table>
<tr>
<td>four</td>
<td>five</td>
</tr>
<tr>
<td>- 4</td>
<td>- 5</td>
</tr>
</table>
thanks.....
|
|

May 24th, 2006, 07:53 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I don't really understand what you're trying to do. But this key
<xsl:key name="x" match="Field/@label" use="generate-id((self::Field[@pos='top']|following-sibling::Field[@label='End'])[last()])"/>
is nonsense. The match pattern matches attributes, which means that the use expression will never select anything, because the attribute can't match self::Field, and an attribute has no following siblings.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

May 24th, 2006, 08:24 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi I just need the nodes between the type=Separator and type=End
|
|

May 24th, 2006, 08:38 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>Hi I just need the nodes between the type=Separator and type=End
XSLT 2.0 solution:
<xsl:variable name="s" select="Field[@type='Separator']"/>
<xsl:variable name="e" select="Field[@type='End']"/>
<xsl:for-each select="*[. >> $s and . << $e]">
...
Sorry, the XSLT 1.0 solutions to such problems are just too much like hard work and I can't summon up the enthusiasm to tackle them. But I think your problem is that the key is matching attributes rather than elements.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

May 24th, 2006, 08:40 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
is there any similar examples for this solution in XSLT 1.0? Thanks again..
|
|

May 24th, 2006, 08:56 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ow and I tried
<xsl:for-each select="*[. >> $s and . << $e]">
in XMLSpy xslt 2.0 and it says its not well formed "& expected"
|
|

May 24th, 2006, 09:21 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Sorry, in XSLT the << operator needs to be escaped as &_lt;&_lt; (ignore the underscores)
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

May 24th, 2006, 09:49 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
nope doesnt work
<xsl:for-each select="*[. &_lt;&_lt; $s and . &_lt;&_lt; $e]">
Unknown error
|
|
 |