[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] XSLT real time use of XML to XML Transformation (More Clues)


Subject: RE: [xsl] XSLT real time use of XML to XML Transformation (More Clues)
From: "HEATH ALLISON" <HEATH.ALLISON@xxxxxxxxxxxxxxx>
Date: Wed, 11 Jun 2003 12:56:45 -0500

Well I've found out what's happening in my transformNodeToObject code, by outputting the error reason. I get this:

"Invalid at the top level of the document."

I've checked the document for white space, and unwanted characters, I find nothing. Oh joy...

-----Original Message-----
From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx]
Sent: Wednesday, June 11, 2003 11:39 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] XSLT real time use of XML to XML Transformation
(Updated Querry)


Heath,

At 10:55 AM 6/11/2003, you wrote:
>Firstly, Wendell thanks, and it's Heath.

You're welcome.

>Outstanding suggestion, thanks for introducing me to a new concept! It 
>clearly fixes my node-tree problem. I had it pointed out to me on another 
>forum that my following-sibling method would be problematic as the number 
>of Users grew. Your method seems to be a bette solution all around.

There's also an in-between solution that doesn't use keys, just pulls the 
data using following-sibling::CLIENTDATA[1] (and [2] and [3]); but the 
key-based solution is somewhat more robust in the face of anomalous data.

>Now my tree is working perfectly, but I'm still having trouble getting 
>that data to be accessible to my stylesheet.

I'm afraid you're going to have to turn to someone familiar with how to 
configure ASP to elucidate why your second transform isn't running.

BTW if you are pulling all USER nodes with <xsl:apply-templates 
select="//USER" />, you don't need the template <xsl:template 
match="CLIENTDATA"/>, since CLIENTDATA nodes will never be traversed on 
their own. You only need it if you are doing the regulation depth-first 
traversal of the entire document that XSLT will provide for by default. 
(You may want to study up on the XSLT processing model if this is 
mysterious to you.)

Cheers,
Wendell

><?xml version="1.0"?>
><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
>version="1.0">
><xsl:output omit-xml-declaration="yes"/>
><xsl:output indent="yes"/>
>
><xsl:key name="data-by-agent" match="CLIENTDATA"
>use="generate-id(preceding-sibling::USER[1])"/>
>
><xsl:template match="/">
>
><DOCUMENT>
><xsl:apply-templates select="//USER" />
></DOCUMENT>
>
><xsl:for-each select="//AGENT/AGENTNAME">
>If you see <xsl:value-of select="."/> tell him this is the new tree.<BR/>
></xsl:for-each>
>
><xsl:for-each select="//USER">
>If you see <xsl:value-of select="."/> tell him this is the old tree.<BR/>
></xsl:for-each>
>
></xsl:template>
>
><xsl:template match="CLIENTDATA"/>
>
><xsl:template match="USER">
>    <AGENT>
>      <xsl:variable name="thisagentdata"
>        select="key('data-by-agent', generate-id())"/>
>      <AGENTNAME><xsl:value-of select="."/></AGENTNAME>
>      <AGENTID>
>        <xsl:value-of select="$thisagentdata[1]"/>
>      </AGENTID>
>      <AGENTAGE>
>        <xsl:value-of select="$thisagentdata[2]"/>
>      </AGENTAGE>
>      <AGENTSTATUS>
>        <xsl:value-of select="$thisagentdata[3]"/>
>      </AGENTSTATUS>
>    </AGENT>
></xsl:template>
>
></xsl:stylesheet>
>
>and my ASP:
>
><%
>'load the data
>set source = server.createObject("Msxml2.DOMDocument")
>source.async = false
>dataFile = Server.mappath("convertxml.xml")
>source.load dataFile
>
>'load stylesheet
>set XSLDoc = server.createObject("Msxml2.DOMDocument")
>XSLDoc.async = false
>stylesheetfile=server.mappath("convertxml_2.xsl")
>XSLDoc.load stylesheetfile
>
>Response.Write "<B>everthing after this line is the first transformation 
><BR></B>"
>response.write source.transformNode(XSLDoc)
>Response.Write "<B>everthing before this line is the first transformation 
><BR></B>"
>
>
>'maker do
>set newSource = server.createObject("Msxml2.DOMDocument")
>newSource.async = False
>newSource.validateOnParse = True
>source.transformNodeToObject XSLDoc,newSource
>
>Response.Write "<B>everthing after this line is the second 
>transformation</B><BR>"
>response.write newSource.transformNode(XSLDoc)
>Response.Write "<B>everthing before this line is the second 
>transformation</B><BR>"
>
>%>
>
>I get this output:
>
><B>everthing after this line is the first transformation <BR></B>
><DOCUMENT>
>         <AGENT>
>                 <AGENTNAME>Agent Smith</AGENTNAME>
>                 <AGENTID>Asmith</AGENTID>
>                 <AGENTAGE>33</AGENTAGE>
>                 <AGENTSTATUS>Agent</AGENTSTATUS>
>         </AGENT>
>         <AGENT>
>                 <AGENTNAME>Agent Clyde</AGENTNAME>
>                 <AGENTID>Aclyde</AGENTID>
>                 <AGENTAGE>35</AGENTAGE>
>                 <AGENTSTATUS>Agent in Training</AGENTSTATUS>
>         </AGENT>
></DOCUMENT>
>If you see Agent Smith tell him this is the old tree.<BR />
>If you see Agent Clyde tell him this is the old tree.<BR />
><B>everthing before this line is the first transformation <BR></B>
>
><B>everthing after this line is the second transformation</B><BR>
><B>everthing before this line is the second transformation</B><BR>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

___&&__&_&___&_&__&&&__&_&__&__&&____&&_&___&__&_&&_____&__&__&&_____&_&&_
     "Thus I make my own use of the telegraph, without consulting
      the directors, like the sparrows, which I perceive use it
      extensively for a perch." -- Thoreau


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords