Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 22nd, 2003, 02:17 PM
Authorized User
 
Join Date: Nov 2003
Location: Hollywood, Fl, USA.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default transformNode with xsl:script

Hello, all

I have a stylesheet with the following namespaces

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:js="javascript:code"
>

When viewing the XML that points to my stylesheet, everything displayes fine, however when performing the transformNode to render HTML, I get the namespace attributes inserted as attributes to my table as follows:

<table cellpadding="0" cellspacing="0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:js="javascript:code"><tr>...

Any clues as to why this is happening?


thanks
__________________
thanks
Reply With Quote
  #2 (permalink)  
Old November 25th, 2003, 11:46 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

All in scope namespaces are included, just in case. You can prevent display if they are not needed anywhere by including the following in your stylesheet element:
Code:
exclude-result-prefixes="msxml js"
Joe (MVP - xml)
Reply With Quote
  #3 (permalink)  
Old November 25th, 2003, 12:35 PM
Authorized User
 
Join Date: Nov 2003
Location: Hollywood, Fl, USA.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

The problem in this case is that my top level template is being ignored alltogether, and when entering this template, it's inserting my stylesheet attributes into my "Table" tag. It almost seems like a bug, but I have tried using the transformation with both Microsoft.XMLDOM and MSXML2.DOMDocument. Same result.

Am I missing something?

thanks
Reply With Quote
  #4 (permalink)  
Old November 25th, 2003, 01:15 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I don't understand what you mean by 'template is being ignored'. Did you make the changes I suggested? If it's still outputting incorrectly show us the full stylesheet and a small source xml example.

Joe (MVP - xml)
Reply With Quote
  #5 (permalink)  
Old November 25th, 2003, 10:58 PM
Authorized User
 
Join Date: Nov 2003
Location: Hollywood, Fl, USA.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

My template is as follows:

<?xml version="1.0"?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:js="javascript:code"
>
    <xsl:template match="/">
            <STYLE class="text/css">
                table{
                    border-style: solid;
                    border-width: 0 1 1 0;
                    border-color: #000000;
                }
                td{
                    border-style: solid;
                    border-width: 1 0 0 1;
                    border-color: #000000;
                    text-align: center;
                    padding: 0 0 0 0;
                    margin: 0 0 0 0;
                    font-family: arial;
                    font-size: 11px;
                }
                .tableNumbers{
                    font-family: arial;
                    font-size: 11px;
                    padding: 0 5 0 5;
                    text-align: right;
                    margin: 0 0 0 0;
                    background-color: #DDDDDD;
                    color: #0000FF;
                }
                .title1{
                    font-size: 14px;
                    font-family: arial;
                    font-weight: 600;
                    background-color: #DDDDDD;
                    color: #0000FF;
                }

            </STYLE>
            <xsl:variable name="pg" select="number(1)" />
            <table cellpadding="0" cellspacing="0" width="600">
                <tr>
                    <td colspan="4" class="title1">
                        Cross Report - Page:#xA0;
                        <xsl:value-of select="$pg" />
                        #xA0;of
                        <xsl:value-of select="count(//PageVLSubset)" />
                    </td>
                </tr>
                <tr>
                    <td width=" 110" class="tableNumbers">Recording Type:</td>
                    <td width=" 190" ><xsl:value-of select="//PIRoot/txtRecordingType" />#xA0;</td>
                    <td width=" 110" class="tableNumbers">Translated By:</td>
                    <td width=" 190" ><xsl:value-of select="//PIRoot/txtTranslatedBy" />#xA0;</td>
                </tr>
                <tr>
                    <td class="tableNumbers">Show:</td>
                    <td><xsl:value-of select="//PIRoot/txtShow" />#xA0;</td>
                    <td class="tableNumbers">Client:</td>
                    <td><xsl:value-of select="//PIRoot/txtClient" />#xA0;</td>
                </tr>
                <tr>
                    <td class="tableNumbers">Recording Began:</td>
                    <td><xsl:value-of select="//PIRoot/txtDateRecordingBegan" />#xA0;</td>
                    <td class="tableNumbers">Adapted By:</td>
                    <td><xsl:value-of select="//PIRoot/txtAdaptedBy" />#xA0;</td>
                </tr>
                <tr>
                    <td class="tableNumbers">Series:</td>
                    <td><xsl:value-of select="//PIRoot/txtSeries" />#xA0;</td>
                    <td class="tableNumbers">Job Number:</td>
                    <td><xsl:value-of select="//PIRoot/txtJobNumber" />#xA0;</td>
                </tr>
            </table><br/>
            <xsl:apply-templates select="/" />
    </xsl:template>


    <msxsl:script language="javascript" implements-prefix="js">
        <![CDATA[
            function getTableNodeset( nFrom, nTo ){
                var XMLDOM = new ActiveXObject ("Microsoft.XMLDOM")
                var temp = XMLDOM.createElement("temp")
                var line
                for ( i=nFrom; i <= nTo; i++ ){
                    line = XMLDOM.createElement("line")
                    line.setAttribute( "n", i )
                    temp.appendChild(line)
                }

                return temp;
            }
        ]]>
    </msxsl:script>


    <xsl:template match="//PageVLSubset[1]">
        <xsl:variable name="nodesFrom" select="number(1)" />
        <xsl:variable name="nodesTo" select="number(50)" />
        <xsl:variable name="charNodes" select="character" />


        <table cellpadding="0" cellspacing="0">
            <tr>
                <td/>
                <xsl:for-each select="character">
                    <td>
                        <applet code="RotatedTextApplet.class" width="25" height="150">
                            <param name="charName">
                                <xsl:attribute name="value"><xsl:value-of select="@name" /></xsl:attribute>
                            </param>
                        </applet>
                    </td>
                </xsl:for-each>
            </tr>
            <xsl:for-each select="js:getTableNodeset ( $nodesFrom, $nodesTo )/line" >
                <tr>
                    <td class="tableNumbers"><xsl:variable name="n" select="@n" /><xsl:value-of select="$n" /></td>
                    <xsl:for-each select="$charNodes">
                        <td>
                                #xA0;
                                <xsl:if test="count( vLoop[@loopNumber=$n] )>0">
                                    <xsl:value-of select="vLoop[@loopNumber=$n]/@loopCount" />
                                </xsl:if>
                                #xA0;
                        </td>
                    </xsl:for-each>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>

    <xsl:template match="text()" />
</xsl:stylesheet>


thanks
Reply With Quote
  #6 (permalink)  
Old November 25th, 2003, 11:00 PM
Authorized User
 
Join Date: Nov 2003
Location: Hollywood, Fl, USA.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

This is my XML

- <REPORTS_ROOT>
+ <CastingReport>
- <character name="MONA" firstAppearance="01.01.04" firstAppVL="1" appearances="54" totalLoops="45">
  <vLoop loopNumber="1" loopCount="11" />
  <vLoop loopNumber="2" loopCount="1" />
  <vLoop loopNumber="3" loopCount="1" />
  <vLoop loopNumber="10" loopCount="1" />
  <vLoop loopNumber="11" loopCount="1" />
  <vLoop loopNumber="12" loopCount="1" />
  <vLoop loopNumber="13" loopCount="2" />
  <vLoop loopNumber="14" loopCount="1" />
  <vLoop loopNumber="15" loopCount="2" />
  <vLoop loopNumber="16" loopCount="1" />
  <vLoop loopNumber="17" loopCount="1" />
  <vLoop loopNumber="18" loopCount="1" />
  <vLoop loopNumber="53" loopCount="1" />
  <vLoop loopNumber="54" loopCount="1" />
  <vLoop loopNumber="55" loopCount="2" />
  <vLoop loopNumber="56" loopCount="1" />
  <vLoop loopNumber="57" loopCount="5" />
  <vLoop loopNumber="126" loopCount="1" />
  <vLoop loopNumber="127" loopCount="1" />
  <vLoop loopNumber="147" loopCount="1" />
  <vLoop loopNumber="148" loopCount="1" />
  <vLoop loopNumber="149" loopCount="1" />
  <vLoop loopNumber="150" loopCount="1" />
  <vLoop loopNumber="206" loopCount="1" />
  <vLoop loopNumber="257" loopCount="1" />
  <vLoop loopNumber="258" loopCount="1" />
  <vLoop loopNumber="277" loopCount="1" />
  <vLoop loopNumber="280" loopCount="1" />
  </character>
- <character name="HOMBRE 1" firstAppearance="01:01.35" firstAppVL="1" appearances="7" totalLoops="7">
  <vLoop loopNumber="1" loopCount="1" />
  <vLoop loopNumber="39" loopCount="1" />
  <vLoop loopNumber="60" loopCount="1" />
  <vLoop loopNumber="81" loopCount="1" />
  <vLoop loopNumber="83" loopCount="1" />
  <vLoop loopNumber="99" loopCount="1" />
  <vLoop loopNumber="230" loopCount="1" />
  </character>
...
  </PageVLSubset>
  </CrossReport>
  </REPORTS_ROOT>

The deal is, there is a template with match="/", which is being ignored, and the stylesheet attributes are being inserted in the table as follows (this is a pasted section of the actual rendered HTML):

<?xml version="1.0" encoding="UTF-16"?>
<table cellpadding="0" cellspacing="0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:js="javascript:code"><tr><td/><td><applet code="RotatedTextApplet.class" width="25" height="150"><param name="charName" value="MONA"/></applet></td>...

I have been banging my head for a week just looking at the code, but everything looks fine.

thanks
Reply With Quote
  #7 (permalink)  
Old November 25th, 2003, 11:02 PM
Authorized User
 
Join Date: Nov 2003
Location: Hollywood, Fl, USA.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

There is a PageVLSubset and CrossReport open tags, I just didn't do the paste right.

thanks
Reply With Quote
  #8 (permalink)  
Old November 26th, 2003, 05:51 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

The style sheet "atrributes" are not being added and a template matching root cannot be ignored unless you have more than one or a mode attribute on it, which you don't. You said you needed namespaces so the template adds them to elements. If you don't want them to appear in the result document CHANGE THE STYLESHEET ELEMENT TO THE FOLLOWING:
Code:
<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
    xmlns:js="javascript:code"
    exclude-result-prefixes="msxml js">
As I don't have your xml (do the missing tags come right after CastingReport) I couldn't test it fully but I'm fairly sure you don't need the JavaScript parts anyway, you can do what you want with pure xslt.

Joe (MVP - xml)
Reply With Quote
  #9 (permalink)  
Old November 26th, 2003, 09:40 AM
Authorized User
 
Join Date: Nov 2003
Location: Hollywood, Fl, USA.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

Thanks, Joe

I am a n00b to XML, and I am sure I can do away with the JavaScript. I am not very happy about instantiating an XMLDOM COM object from within the stylesheet just to get a set of 50 nodes to use as a nodeset for a xsl:for-each. There must be a way to implement a counter for loop as opposed to a for loop that iterates through a collection of nodes.

Also, Yes, the missing nodes to appear immediately after the CastingReport

Joe, I am very appreciative of all the help you are providing me with and I beg you to be patient with my ignorance on the subject. In your first reply, I didn't even know where to add the exclude-result-prefixes you suggested.

If you check my HTML, in the table tag, immediately after the <?xml?>, you'll see attributes added to the tag, which clearly shouldn't be there. These attributes correspond to the StyleSheet attributes of my XSL stylesheet. I think that's an indicative that something is wrong with my stylesheet declaration. I will add the entry you suggested and see what happens. What exactly does it do?

If it's not too much trouble, or too much to ask, testing it out with the xml would be an enormous help. When stating that the top level template was ignored, I'm referring to the one with the match="/". As you can see, it contains HTML tags, Cascading Stylesheets and what have you. When viewing the XML in a browser, with a call to the xsl stylesheet, this template is interpreted and I can view the colors and what not, but when rendering HTML, as you can see by the HTML rendered, these elements are nowhere to be found, hence my suggesting that the top level template may have been ignored.

There are several things I am working with here for the first time. First, I have never used xsl:script. I have actually made several attempts, this one being the most successful, second, I have never instantiated a COM object from within the template, though I don't think the latter may be causing the problem due to the correct interpretation of the XML with the XSL call.

Joe, if it's more helpful, I would like to extend an invitation to continue via one of chat medias, be it AIM, MSN, Yahoo, etc. You probably know where to find my Nicks or Screen Names

Cheers and thanks once again

thanks
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Horizontal Menubar using XSL and Java Script aaron385 XSLT 2 July 16th, 2008 03:09 AM
transformNode not working in firefox picky Javascript 0 December 20th, 2007 01:54 AM
How to assign xsl param with java script varaible Sanjay.Verma XSLT 1 November 21st, 2006 04:34 AM
transformNode w/2 source XML docs? kwilliams XSLT 0 July 25th, 2005 03:38 PM
XLST transformNode problem beyondtron Classic ASP XML 0 February 4th, 2004 04:52 PM



All times are GMT -4. The time now is 05:47 AM.


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