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 March 8th, 2006, 10:49 AM
Registered User
 
Join Date: Mar 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Generating anchor tags

When I am building a table of summary values from my xml I'd like to generate an <a href='# + the xsl:value-of an element (an element such as <abc>100</abc> and then <abc>200</abc> for the next item, etc.) + '> so my result looks like <a href='#100'>100</a> and then further down in my result document where I use this value-of in a for-each detail section (to show the 100 details and then the 200 details, etc.) I would also need to generate the anchor, such as <a name='100'></a> at the beginning of the first loop, then <a name='200'></a> at the next loop, etc.

Maybe a better way to describe this is I am creating a kind of table of contents with my summary table at the start of my output doc. The user wants click on an underlined key to jump to the appropriate detail section below.

Do I put the xsl:value-of into a variable first and then somehow concatenate that into my anchor tags? Is there an example of this in Michael's XSLT Programmers Reference book?

Thanks.
 
Old March 8th, 2006, 11:17 AM
Registered User
 
Join Date: Mar 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found info on page 492 of Michael's book for using generate-id() and can see the generated id when I hover over my hyperlink but it does not jump down the document to the anchor spot.

Here is a sample of the relevant XML:

<BillingProvider>
            <LX>
                <LX01>1</LX01>
            </LX>
            <TS3>
                <TS301>105590000</TS301>
                <TS302>11</TS302>
                <TS303>20041231</TS303>
                <TS304>10</TS304>
                <TS305>7395.6</TS305>
                <TS306>0</TS306>
                <TS307>0</TS307>
                <TS308>7395.6</TS308>
                <TS309>0</TS309>
            </TS3>
            <ClaimLineItem>

etc.... Further on down the <BillingProvider> section closes and a new one begins.

Here is my xslt that generates the summary table:

<xsl:for-each select="BillingProvider">
            <tr>
                <td><a href="#{generate-id(TS3/TS301)}">
                    <xsl:value-of select="TS3/TS301"></xsl:value-of></a>
                </td>
                <td align="right">
                    <xsl:value-of select="TS3/TS304"></xsl:value-of>
                </td>
                <td align="right">
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="format-number(TS3/TS305,'#,###.00')"></xsl:value-of>
                </td>
                <td align="right">
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="format-number(TS3/TS306,'#,###.00')"></xsl:value-of>
                </td>
                <td align="right">
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="format-number(TS3/TS308,'#,###.00')"></xsl:value-of>
                </td>
                <td align="right">
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="format-number(TS3/TS309,'#,###.00')"></xsl:value-of>
                </td>
            </tr>
        </xsl:for-each>

And here is the start of my detail section template:

    <xsl:template match="File/Detail/BillingProvider">

        <tr><a name="{generate-id()}"></a>
            <td colspan="17"><strong>[u]
                <xsl:value-of select="TS3/TS301"/>
                <xsl:variable name="billingproviderid" select="TS3/TS301"></xsl:variable>
                </u></strong>
            </td>
        </tr>



    <tr>
        <td class="Z">Client<br/>ID</td>
        <td class="Z">TCN</td>
        <td class="Z">Remit<br/>Line #</td>
        <td class="Z" valign="top">First</td>
        <td class="Z" valign="top">Middle</td>
        <td class="Z" valign="top">Last</td>
        <td class="Z">Mainecare<br/>ID</td>
        <td class="Z">Service<br/>From</td>
        <td class="Z">Service<br/>To</td>
        <td class="Z">Procedure<br/>Code</td>
        <td class="Z">Srvc Prov<br/>ID</td>
        <td class="Z">Units</td>
        <td class="Z">Billed</td>
        <td class="Z">Paid</td>
        <td class="Z">Adj.</td>
        <td class="Z">Code</td>
        <td class="Z">Remark</td>
    </tr>



        <xsl:for-each select="ClaimLineItem">
        <xsl:sort select="NM1/NM103"/>
            <tr>
                <td>

                <xsl:choose>
                    <xsl:when test="$billingproviderid = '105590000'">
                        <xsl:value-of select="translate(substring(CLP/CLP01,1,5),'XXX',' ')"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>NA</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
                </td>
etc....

So, I'm maybe halfway there but, again, the name anchor tags (<a name=xxxx></a> do not appear to be working.


 
Old March 8th, 2006, 01:17 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The anchor <a name=""> contains the generate-id() of a BillingProvider element. The link <a href=""> contains the generate-id() of a TS301 element. These aren't going to match.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 8th, 2006, 03:05 PM
Registered User
 
Join Date: Mar 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah, so you made me look closer at what I was doing. So...

I changed this:
<a href="#{generate-id(TS3/TS301)}">

To this:
<a href="#{generate-id(.)}">

And, success!





Similar Threads
Thread Thread Starter Forum Replies Last Post
really stupid problem with anchor tags thenoseknows ASP.NET 2.0 Basics 3 August 31st, 2006 09:34 AM
Generating html tags dynamically sachin lad Servlets 1 April 26th, 2005 05:35 PM
Generating XML tags on the fly francislang XSLT 3 September 6th, 2004 05:21 AM
Anchor Tags don't work on iMac DenimDog HTML Code Clinic 3 October 30th, 2003 03:00 PM
Anchor Tags and the onClick event Blaise Javascript 4 June 16th, 2003 04:58 AM





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