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 May 18th, 2007, 07:46 PM
Registered User
 
Join Date: May 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default xpath query

I got a xml code:
<list>
    <student>
        <name>dave</name>
        <adres>old trafford</adres>
        <adres>manchester,england</adres>
    </student>
    <student>
        <name>paul</name>
        <adres>old trafford</adres>
        <adres>manchester,england</adres>
    </student>
</list>


how do i output name+ the 2 adress lines.

I tried:
<xsl:template match="/">
    <xsl:for-each select="list/student">
        <xsl:value-of select="name"/>
        <xsl:value-of select="adres"/>
    </xsl:for-each>
</xsl:template>
But it only outputs 1 line of address.How do i output both the lines of address ?

 
Old May 19th, 2007, 02:44 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Instead of:
Code:
<xsl:value-of select="adres"/>
try
Code:
<xsl:apply-templates select="adres"/>
and add a template:
Code:
<xsl:template match="adres">
  <xsl:value-of select="."/>

  <xsl:if test="position() != last()">, </xs:if>  
</xsl:template>
Your code would work in version 2.0 where value-of returns a space separated list rather than just the first matching node.

--

Joe (Microsoft MVP - XML)
 
Old May 19th, 2007, 03:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You iterate over the adres elements exactly the same way as you iterate over the student elements, with an xsl:for-each.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
XPATH pallone XSLT 4 November 19th, 2006 07:50 PM
Read xpath query from node value jaquing XSLT 2 January 11th, 2006 06:50 PM
XPath rupen XML 2 April 19th, 2005 09:43 AM
Binding Results of an Xpath query to a datagrid cowa ADO.NET 2 November 17th, 2003 02:40 AM
.NET XPath query not coming out right perropicante C# 0 June 15th, 2003 10:53 AM





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