xsl-list
[Top] [All Lists]

Re: [xsl] Transforming XML copied via XSLT

2010-01-27 16:45:06
On Wed, 2010-01-27 at 23:31 +0100, Imsieke, Gerrit, le-tex wrote:
Ok, one last try.

saxon -it:html -xsl:test2.xsl -o:menu.html

---food.xml----- (Input)
<?xml version="1.0"?>
<food>
   <sandwich>
     <name>tuna</name>
     <link>mysite.com</link>
     <price>$5.00</price>
   </sandwich>
</food>
---/food.xml-----

---test2.xsl----
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   xmlns:html="http://www.w3.org/1999/xhtml";
   xmlns:saxon="http://saxon.sf.net/";
   version="2.0"
   exclude-result-prefixes="html saxon">

   <xsl:output
     method="xml"
     indent="yes"
     doctype-public = "-//W3C//DTD XHTML 1.1//EN"
     doctype-system = 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
     saxon:suppress-indentation="p h1 h2 h3 h4 h5 h6 title"
     />

   <xsl:template name="html">
     <html>
       <head>
         <title>Menu</title>
       </head>
       <body>
         <h1>Menu</h1>
         <h2>Sandwiches</h2>
         <ul>
           <xsl:for-each select="document('food.xml')//sandwich">
             <li>
               <xsl:apply-templates select="."/>
             </li>
           </xsl:for-each>
         </ul>
       </body>
     </html>
   </xsl:template>

   <xsl:template match="sandwich">
     <p>
       <a href="http://{link}";>
         <xsl:value-of select="name"/>
       </a>
     </p>
     <p>
       <xsl:value-of select="price"/>
     </p>
   </xsl:template>

</xsl:stylesheet>
---/test2.xsl------


---menu.html----- (Output)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
   PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html>
    <head>
       <title>Menu</title>
    </head>
    <body>
       <h1>Menu</h1>
       <h2>Sandwiches</h2>
       <ul>
          <li>
             <p><a href="http://mysite.com";>tuna</a></p>
             <p>$5.00</p>
          </li>
       </ul>
    </body>
</html>
---/menu.html-------


Gerrit


On 27.01.2010 22:59, Rob Belics wrote:
No, perhaps this will better explain:

The input xml file might be:
<sandwich>
    <name>tuna</name>
    <link>mysite.com</link>
    <price>$5.00</price>
</sandwich>

I'm able to 'xsl:copy-of' into my file but I'm not sure the best way to
obtain these results:
<a href="http://mysite.com/";>tuna</a>
<p>$5.00</p>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or 
e-mail:<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



I re-thought how I was approaching this and may have found the solution.
My new approach seems to work, and still uses copy-of, but I need to
look at your suggestion of using call-template or apply-templates along
with reviewing this post.

I hope to post back what works or doesn't tomorrow. Thanks for the help.

btw, I've read the books and the docs. This is my first attempt at
something complicated; at least complicated for me.


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--