Re: XML from html out of XSL

Subject: Re: XML from html out of XSL
From: Bill Martschenko <billmartschenko@xxxxxxxxx>
Date: Tue, 28 Sep 1999 19:59:51 -0700 (PDT)
Even simpler solution...

Excerpt from
http://msdn.microsoft.com/xml/xslguide/browsing-xsl.asp#browsing-xsl-script

<excerpt>
The HTML that results from browsing XML with an XSL
style sheet is fully scriptable using the Introduction
to the Dynamic HTML Object Model. In addition, there
are two properties available on the DHTML document
object that provide script access to the XML and XSL
documents:

The document.XMLDocument property returns the root
node of the XML source document. 
The document.XSLDocument property returns the root
node of the XSL style sheet document. 
</excerpt>


--- Bill Martschenko <billmartschenko@xxxxxxxxx>
wrote:
> Use XML islands.  Specifically, when you generate
> HTML
> with your XSL, generate an XML island <xml
> id="data">...</xml> that contains a copy of the
> original XML.  Use some programmatic id, such as
> "data", in the xml island so you can
> programmatically
> reference it.
> 
> I've attached a sample that does this.
> 
> Notes about the sample.
> 
> 1) A small table is populated directly from the XSL.
> 
> 2) A trivial programmatic access to the original xml
> is in the ondatasetcomplete handler.
> 
> 3) The data.readystate property does not get set to
> "complete" in the onload() event handler for the
> window object or the body.  Instead, I use a
> specific
> ondatasetcomplete handler for the xml island itself.
> 
> 4) A second table shows the original XML as a
> reference table.  It uses the xml island as a DSO. 
> This is a second type of programmatic access.
> 
> Let met know if this is not what you need,
> Bill
> 
> >From: Siegfried Haag
> <Siegfried.Haag@xxxxxxxxxxxxxx>
> >Date: Fri, 24 Sep 1999 15:31:37 +0100
> >Organization: SAG Systemhaus GmbH
> >
> >Hi,
> >
> >i have a html-page created out of applying xsl on
> xml-document.
> >
> >How can i access the hole xml with javascript in
> the
> html?
> >
> >---------------
> >more exactly: 
> >a.xml with a reference to a style b.xsl
> >a.xml is startet by the browser IE5
> >automatically the b.xsl is loaded after a.xml 
> >and the style b.xsl is applied
> >
> >the result is a html-page with javascript in it
> >and a function in the body:
> >	body onLoad="doit()";
> >
> >in the function i want to access the XML-DOM in the
> memory
> >of the browser
> >
> >but i have no name of it!?
> >
> >when i load the xml by object.load("abc.xml") then
> i
> have
> >it, but thats not the solution
> >
> >Anybody who knows a bit more?
> >
> >Thank you,
> >
> >Siegfried Haag
> >Software AG
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Bid and sell for free at http://auctions.yahoo.com>
<?xml version="1.0"?>
> <?xml-stylesheet type="text/xsl" href="loonies.xsl"
> ?>
> <loonies>
>   <toon>
>     <character>Sylvester</character>
>     <type>cat</type>
>     <likes-to-pound>Tweety</likes-to-pound>
>   </toon>
>   <toon>
>     <character>Tweety</character>
>     <type>bird</type>
>   </toon>
>   <toon>
>     <character>Tweety's friend</character>
>     <type>dog</type>
>     <likes-to-pound>Sylvester</likes-to-pound>
>   </toon>
>   <toon>
>     <character>Tom</character>
>     <type>cat</type>
>     <likes-to-pound>Jerry</likes-to-pound>
>   </toon>
>   <toon>
>     <character>Jerry</character>
>     <type>mouse</type>
>     <likes-to-pound>Tom</likes-to-pound>
>   </toon>
> </loonies>
> > <?xml version='1.0'?>
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/TR/WD-xsl";>
>     <xsl:template match="/">
> 
> <html>
>     <body bgcolor="#EEE8AA">
>         <!-- Create a copy of the original XML in an
> XML island. -->
>         <!-- Give it an id so that the original XML
> can be       -->
>         <!-- programmatically accessed.             
>             -->
>         <!--                                        
>             -->
>         <!-- Also, set up an event handler for when
> the XML data -->
>         <!-- is available.                          
>             -->
>         <script for="xmlisland"
> event="ondatasetcomplete">
>             var node =
>
xmlisland.XMLDocument.selectSingleNode("loonies/toon/character");
>            
> window.alert("xmlisland_ondatasetcomplete:  1st
> character = '" + node.text + "'");
>             <!-- Note that the predicate
> (xmlisland.readystate == "complete") -->
>             <!-- is false.  No explanation though
> the data is available.      -->
>         </script>
>         <xml id="xmlisland">
>             <xsl:apply-templates select="/">
>                 <xsl:template>
>                     <xsl:copy>
>                         <!-- Note that we leave off
> pi() in select below -->
>                         <xsl:apply-templates
> select="@* | * | text()"/>
>                     </xsl:copy>
>                 </xsl:template>
>             </xsl:apply-templates>          
>         </xml>
> 
>         <!-- use XSL to build a table of cats that
> like-to-pound -->
>         <h2>Looney cats that like to pound other
> toons:</h2>
>         <table border="1">
>            
> <thead><th>Toon</th><th>Victim</th></thead>
>             <xsl:for-each
> select="//toon[type='cat'][likes-to-pound]">
>                 <tr>
>                     <td><xsl:value-of
> select="character"/></td>
>                     <td align="center"><xsl:value-of
> select="likes-to-pound"/></td>
>                 </tr>
>         </xsl:for-each>
>         </table>
> 
>         <br></br> 
>         <br></br>
>         <h2>Looney Toon Reference</h2>
>         <h3>(A copy of the original XML fed to the
> XSL)</h3>
>         <table datasrc="#xmlisland" border="1">
>            
> <thead><th>Toon</th><th>Type</th><th>Likes to
> Pound</th></thead>
>             <tr>
>                 <td><span
> datafld="character"></span></td>
>                 <td align="center"><span
> datafld="type"></span></td>
>                 <td align="center"><span
> datafld="likes-to-pound"></span></td>
>             </tr>
>         </table>
>     </body>
> </html>
> 
>     </xsl:template>
> </xsl:stylesheet>
> 

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com


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


Current Thread