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 October 7th, 2006, 04:24 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default Help with HREF string

Hi All,

I am having trouble creating an HREF string based on an element and an attribute from another element. I want to combine the value of <link> with the value of JBU:revTEXT@name. Combining these two would create the link. The combined link would need to be on this line:

                                                                <td>
                                                                    <a href="{current()/@name}">
                                                                        <xsl:apply-templates/>
                                                                    </a>
                                                                </td>

Code:
<xsl:for-each select="$XML1">
                            <xsl:for-each select="book">
                                <xsl:for-each select="manual">
                                    <xsl:for-each select="title">
                                        <tr>
                                            <td>
                                                <a>
                                                    <xsl:attribute name="href"><xsl:value-of select="../link"/></xsl:attribute>
                                                    <xsl:for-each select="document(.)">
                                                        <xsl:for-each select="id('title')">
                                                            <xsl:apply-templates/>
                                                        </xsl:for-each>
                                                        <xsl:for-each select="//JBU:revTEXT[@*]">
                                                            <tr>
                                                                <td>
                                                                    <xsl:for-each select="id('title')">
                                                                        <xsl:apply-templates/>
                                                                    </xsl:for-each>
                                                                </td>
                                                                <td>
                                                                    <xsl:for-each select="id('revdate')">
                                                                        <xsl:apply-templates/>
                                                                    </xsl:for-each>
                                                                </td>
                                                                <td>
                                                                    <xsl:value-of select="."/>
                                                                </td>
                                                                <td align="center">
                                                                    <xsl:for-each select="id('revnumber')">
                                                                        <xsl:apply-templates/>
                                                                    </xsl:for-each>
                                                                </td>
                                                                <td>
                                                                    <a href="{current()/@name}">
                                                                        <xsl:apply-templates/>
                                                                    </a>
                                                                </td>
                                                            </tr>
                                                        </xsl:for-each>
                                                    </xsl:for-each>
                                                </a>
                                            </td>
                                        </tr>
                                        <br/>
                                    </xsl:for-each>
                                </xsl:for-each>
                            </xsl:for-each>
                        </xsl:for-each>
                    </tbody>
                </table>
            </body>
        </html>
    </xsl:template>


Thanks for the help.

 
Old October 7th, 2006, 07:41 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Ok, I am almost there. I am able to create the string with the concat(). I think my xpath expression is wrong:

<xsl:variable name="x" select="../Link"/>

here is my XML file:
<book>
    <manual>
        <title>Chapter9a.xml</title>
        <link>Chapter 9.html</link>
    </manual>

</book>


<a href="{concat($x,'#',current()/@name)}">





            <xsl:for-each select="$XML1">
                            <xsl:for-each select="book">
                                <xsl:for-each select="manual">
                                    <xsl:for-each select="title">
                                        <tr>
                                            <td>
                                                <a>
                                                    <xsl:attribute name="href"><xsl:value-of select="../link"/><xsl:variable name="x" select="../Link"/></xsl:attribute>
                                                    <xsl:for-each select="document(.)">
                                                        <xsl:for-each select="id('title')">
                                                            <xsl:apply-templates/>
                                                        </xsl:for-each>
                                                        <xsl:for-each select="//JBU:revTEXT[@*]">

                                                            <tr>
                                                                <td>
                                                                    <xsl:for-each select="id('title')">
                                                                        <xsl:apply-templates/>
                                                                    </xsl:for-each>
                                                                </td>
                                                                <td>
                                                                    <xsl:for-each select="id('revdate')">
                                                                        <xsl:apply-templates/>
                                                                    </xsl:for-each>
                                                                </td>
                                                                <td>
                                                                    <xsl:value-of select="."/>
                                                                </td>
                                                                <td align="center">
                                                                    <xsl:for-each select="id('revnumber')">
                                                                        <xsl:apply-templates/>
                                                                    </xsl:for-each>
                                                                </td>
                                                                <td>
                                                                    <a href="{concat($x,'#',current()/@name)}">
                                                                        <xsl:apply-templates/>
                                                                    </a>
                                                                </td>
                                                            </tr>
                                                        </xsl:for-each>
                                                    </xsl:for-each>
                                                </a>
                                            </td>
                                        </tr>
                                        <br/>
                                    </xsl:for-each>
                                </xsl:for-each>
                            </xsl:for-each>
                        </xsl:for-each>
 
Old October 8th, 2006, 06:33 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Doesn't link start with a lowercase l?

--

Joe (Microsoft MVP - XML)
 
Old October 8th, 2006, 07:36 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

ahhhhh that was it. so easy...Sometimes another set of eyes helps. Thanks Joe.

Bones


 
Old October 9th, 2006, 04:39 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You could use

<a>
  <xsl:attribute name="href">
         <xsl:value-of select="xxxx"/>
         <xsl:value-of select="yyyy"/>
  </xsl:attribute>

or

<a href="{xxxx}{yyyy}">

or

<a href="{concat(xxxx, yyyy)}">

or

<a>
  <xsl:attribute name="href">
         <xsl:value-of select="concat(xxxx, yyyy)"/
  </xsl:attribute>

I cana't help you with xxxx and yyyy because you haven't said anything about your source document (you've just shown 50 lines of stylesheet code which don't seem to have any obvious relevance to your question)


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 9th, 2006, 04:43 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

How do I call up a varable within a concat()?

<a href="{concat($x,'#',current()/@name)}">


You seem to have answered your own question.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 9th, 2006, 05:33 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Michael,

As always, thank you for the help. You are correct, I did answer my own question. Somestime writing out the question helps me look at this in a different light.

 
Quote:
quote:I cana't help you with xxxx and yyyy because you haven't said anything about your source document (you've just shown 50 lines of stylesheet code which don't seem to have any obvious relevance to your question)


My source document is actually an XML file that list about 35 XML files. In my orginal question, I was looking for a method to combine strings. After digging through Functions, I found the concat().

My code was correct except my xpath expression. I was looking for "Link" rather than "link". (thanks Joe)

Once again, Thank you for your help.

Bones






Similar Threads
Thread Thread Starter Forum Replies Last Post
REGEX to get href="#" monfu BOOK: Beginning Regular Expressions 2 July 24th, 2008 11:46 AM
Chapter 8, href and HRef (p. 285) roman BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 June 16th, 2008 10:40 AM
Href in a string seran128 Classic ASP Professional 1 April 14th, 2006 11:05 PM
href darkhalf Javascript 2 November 20th, 2005 10:59 AM





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