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 September 11th, 2004, 09:15 PM
Registered User
 
Join Date: Sep 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default transform just one node...

I have a static web page that includes a dhtml table that is built from an xsl transformation. Each row of the table is keyed to a unique value that is associated with a node of my xml file. I was feeling pretty good that I had pulled that one off. Now, when my user clicks in the first column of the table I have a method set up that returns an alert that displays just the node keyed to that value:
    XMLIsland = document.all.XMLdata.XMLDocument;
    alert(XMLIsland.selectSingleNode("//TestGroup[ID='" + currentRow.childNodes(0).innerText + "']").xml)
What I want to do in that same javascript method is blow out the contents of my exisitng DHTML table that is set within a div tag named dhtmlTable and replace the contents with the node that will be transformed with a different xsl file. I've been working on this for three days and just can't get it. How in the world do I transform the selected node with a different xsl and display that html on my web page?

 
Old September 12th, 2004, 05:10 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Perhaps I've misunderstood, if the xslt to be used for the new transform depends on which row clicked then apply the transform to the xml. Providing your table has an immediate parent, maybe a span or a div then set the innerHTML of this to the result of the transformation.

If this isn't what you need can you provide small examples of your xml and html and what you're aiming at?



--

Joe (Co-author Beginning XML, 3rd edition)
 
Old September 12th, 2004, 06:30 AM
Registered User
 
Join Date: Sep 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Following is a cut from my htm that includes a reference to the table header and "tablebody" div tag which builds my dhtml table with a call to a js function from the body tag load function:
        <div id="centerDoc">
            <div>
                <span><b>Selection</b></span>
            </div>

            <DIV id="tableHeader">
                <TABLE width="625" border="1" cellspacing="0">
                    <TR>
                        <TH width="200" onClick="sort('./ID','text');">Test Name</TH>
                        <TH width="150" onClick="sort('./ISO8601','text');">Test Date</TH>
                        <TH width="75" onClick="sort('./Status','text');">Status</TH>
                        <TH width="200" >Report Type</TH>
                    </TR>
                </TABLE>
            </DIV>

            <DIV id="tableBody" style="width:625px;height:110px;overflow:scroll;"> </DIV>
            <XML id="replace" src="test.xsl"></XML>
            <XML id="tableXSL" src="20040903T170000_ICO_testselectiontable.xsl"></XML>
            <XML id="XMLdata" src="20040903T170000_ICO_testselectiontable.xml"></XML>



        </div>

        <div id="displayReport">
        <XML id="replaceTable" src="test.xsl"></XML>
        </div>

This works great. Now, when the user clicks in a row I want to transform just that node using a different xsl and display that contents in the tableBody tag. Following is a cut from my xsl that builds the body of the above table:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="testnumber" select="1" />
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">

<TABLE width="625" border="1" cellspacing="0" bgcolor="white">
<xsl:for-each select="//Test">
    <xsl:sort select="./ID" order="ascending" data-type="text" case-order="lower-first"/>
    <TR id="trnode">
    <xsl:attribute name="onclick">selectRow(this)</xsl:attribute>
    <xsl:attribute name="ondblclick">selectRow(this);selectTestCurren tRow()</xsl:attribute>
    <TD id="idCol" width="200">
        <a href="{./ID/@value}" ><xsl:value-of select="./ID"/></a>
    </TD>
Also, the js method I want to use to do the transformation with just the selected node and the xsl named "replace" mentioned above.
function selectTestCurrentRow()
{
    XMLIsland = document.all.XMLdata.XMLDocument;


    node = XMLIsland.selectSingleNode("//Test[ID='" + currentRow.childNodes(0).innerText + "']").xml;

    alert(node)

    newHTML = XMLIsland .transformNode(document.all.replace.XMLDocument);

    document.getElementById('centerDoc').innerHTML = "";
    document.getElementById('displayReport').innerHTML = newHTML;

}
This works fine up to the alert(). I can display the selected node in the alert but have no idea how to do the transform of the single node with the second style sheet and display it in the bodytag. Boy, I hope I'm making sense :-) I must say tho...I find this XML / XSL thing very interesting. Can someone push me through this? I get a weird error at the transform line that says the stylesheet does not contain a document element? Also, I select the single node so shouldn't I pass that for the transform and not the entire island?






Similar Threads
Thread Thread Starter Forum Replies Last Post
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
Missing Node (Node data) pashworth XSLT 3 January 29th, 2007 12:39 PM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM
document node order vs sort node order. ladyslipper98201 XSLT 2 June 5th, 2003 11:06 AM





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