Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 23rd, 2006, 02:31 PM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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



Reply With Quote
  #2 (permalink)  
Old May 24th, 2006, 04:25 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
Reply With Quote
  #3 (permalink)  
Old May 24th, 2006, 06:12 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


Reply With Quote
  #4 (permalink)  
Old May 24th, 2006, 07:53 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
Reply With Quote
  #5 (permalink)  
Old May 24th, 2006, 08:24 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi I just need the nodes between the type=Separator and type=End

Reply With Quote
  #6 (permalink)  
Old May 24th, 2006, 08:38 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>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
Reply With Quote
  #7 (permalink)  
Old May 24th, 2006, 08:40 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is there any similar examples for this solution in XSLT 1.0? Thanks again..

Reply With Quote
  #8 (permalink)  
Old May 24th, 2006, 08:56 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ow and I tried

<xsl:for-each select="*[. >> $s and . << $e]">

in XMLSpy xslt 2.0 and it says its not well formed "& expected"



Reply With Quote
  #9 (permalink)  
Old May 24th, 2006, 09:21 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
Reply With Quote
  #10 (permalink)  
Old May 24th, 2006, 09:49 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

nope doesnt work
<xsl:for-each select="*[. &_lt;&_lt; $s and . &_lt;&_lt; $e]">

Unknown error

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
c:out doesnt work tllcll JSP Basics 1 November 1st, 2007 03:15 AM
Button doesnt work help john111 Java GUI 4 March 21st, 2006 05:22 PM
ContainsValue doesnt work demitry Generics 1 November 21st, 2005 05:29 PM
WHY DOESNT THIS WORK vb certified Pro VB.NET 2002/2003 5 August 1st, 2005 11:08 PM
Delete Topic doesnt work mehdi62b Forum and Wrox.com Feedback 4 October 4th, 2004 02:02 PM



All times are GMT -4. The time now is 11:56 PM.


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