xsl-list
[Top] [All Lists]

Re: [xsl] Transforming XML copied via XSLT

2010-01-27 16:32:39
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>
--~--


--
Gerrit Imsieke
Geschäftsführer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschäftsführer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard Vöckler

--~------------------------------------------------------------------
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>
--~--