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 June 17th, 2008, 11:05 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default line number in xml using xsl and html link

Hi All,

Im working for a XML files comparison report, generated in html. I get the output as same, different and new. i could get the line number of comparison using saxon:line-number, but I need to give this number as href in html and while this link is clicked in html report, then the actual line of error should be opened in xml. this is what im trying. i wrote a code but it does not go to the correct line but it just opens the xml file. can anyone help me please.

see the snippet below for "same":

    <xsl:template mode="src1" match="TL1Commands">
        <xsl:param name="tl1i"></xsl:param>
        <xsl:param name="tl1cs"></xsl:param>

        <xsl:variable name="tl1c" select="@cmdType"></xsl:variable>

        <td><xsl:value-of select="$tl1c"/></td>
        <td><xsl:value-of select="$tl1i"/></td>
        <td>
            <xsl:choose>
                <xsl:when
                    test="$docB//TL1CommandSection[./Head=$tl1cs]//table[@tabType='TL1CmdImplementation']//tbody/row[.//TL1Commands=$tl1c]">
                    <xsl:choose>
                        <xsl:when
                            test="$docB//TL1CommandSection[./Head=$tl1cs]//table[@tabType='TL1CmdImplementation']//tbody/row[.//TL1Commands=$tl1c][.//TL1Instance=$tl1i]">
                            <a><xsl:attribute name="href"><xsl:value-of select="concat(document-uri($docA), '#', saxon:line-number())"></xsl:value-of></xsl:attribute>Same</a>
                         </xsl:when>
                        <xsl:otherwise>
                            <span class="diff">
                            <xsl:text>Different</xsl:text></span>
                         </xsl:otherwise>
                    </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                    <span class="diff">
                <xsl:text>New</xsl:text></span>
                </xsl:otherwise>
            </xsl:choose>
        </td>
        <td>
            <xsl:choose>
                <xsl:when
                    test="$docB//TL1CommandSection[./Head=$tl1cs]//table[@tabType='TL1CmdImplementation']//tbody/row[.//TL1Commands=$tl1c]">
                    <xsl:choose>
                        <xsl:when
                            test="$docB//TL1CommandSection[./Head=$tl1cs]//table[@tabType='TL1CmdImplementation']//tbody/row[.//TL1Commands=$tl1c][.//TL1Instance=$tl1i]">
                            <span class="same">"<xsl:value-of select="$tl1c"/>"</span> is present with Same instance

                        </xsl:when>
                        <xsl:otherwise>
                            <span class="diff">
                                "<xsl:value-of select="$tl1c"/>" is present with Different instance</span>

                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                    <span class="diff">
                        "<xsl:value-of select="$tl1c"/>" is totally New here</span>

                </xsl:otherwise>
            </xsl:choose>
        </td>
    </xsl:template>



regardsm
rummy

__________________
Rummy
 
Old June 17th, 2008, 11:21 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

So you are trying to generate a link with the line number specified as an anchor (e.g. doc.xml#42). I don't know if any browsers recognize that and scroll to that line. With HTML and XML I think you can specify the id of an element as an anchor (doc.xml#elementId) and the browser is supposed to scroll to that element. But unless your XML has attributes of type ID I don't think that helps.

I am not sure there is a solution, unless you find a browser that interprets the anchor as a line number.



--
  Martin Honnen
  Microsoft MVP - XML
 
Old June 17th, 2008, 11:34 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't think that browsers will recognize a line number as a fragment identifier in an XML URI. I'm not sure they even reliably recognize an ID attribute. I suspect that to do this you'll have to write the code that renders the XML as HTML (that is, serializing <x>123</x> as &lt;x>123&lt;/x>) yourself, inserting HTML anchors in the relevant places to reflect the line numbering.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 17th, 2008, 01:36 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

thank you all for your suggestions






Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT - xml difference with line number mrame XSLT 1 June 4th, 2008 05:49 PM
Rendering HTML inside XML through XSL - HELP !!! jilly XSLT 6 May 23rd, 2007 10:36 AM
xml to html with xsl boblavinsky XSLT 4 January 5th, 2007 05:30 AM
XML/Excel DDE live link to HTML lss XML 0 October 2nd, 2006 09:25 AM
XML/XSL to actual HTML tcstom XML 3 December 9th, 2005 01:36 PM





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