[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] AW: Embedded stylesheets
I have to admit I had problems with most of the examples and then I found one that worked and I based my code on it. it doesn't seeem I made a bookmark to to this example and I can't readily find it (nor can I find the example you are referring to), however below is my working code. it works in xml spy and in xalan. the stylesheet is based on an IBM example. try this. I hope it is useful. <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="application/xml" href="selfcontained.xsl"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:icon="http://www.icongmbh.de/letter"> <letter xmlns="http://www.icongmbh.de/letter"> <body> <para> It was a pleasure to meet you at XML World '99 in Ottawa recently. As promised, I'm enclosing a copy of the "Intro to XML" tutorial CD. I apologize that we were out of CDs when you stopped by our booth. </para> <para> Please let me know if you have any comments on the tutorial, or if you have suggestions for future topics. Over the next few months, we'll be adding new tutorials to the developerWorks web site (www.ibm.com/developerWorks). We'd really like your feedback! </para> </body> <cc-list> <name> <first-name>Dirk</first-name> <last-name>Nicol</last-name> </name> <name> <first-name>Leah</first-name> <last-name>Ketring</last-name> </name> </cc-list> <closing>Sincerely</closing> <date day="28" month="September" year="1999"/> <enclosure>CD-ROM</enclosure> <Reference>Something here</Reference> <return-address> <street>Bimsarkstr 56</street> <city>Suttgart</city> <state>Baden</state> <zip>70197</zip> </return-address> <salutation>Dear Doug</salutation> <signature> <name> <first-name>Doug</first-name> <last-name>Tidwell</last-name> </name> <job-title>Senior Programmer</job-title> </signature> <company>IBM</company> <inside-address> <name> <title>Mrs.</title> <first-name>Mary</first-name> <last-name>McGoon</last-name> </name> <street>1401 Main Street</street> <city>Anytown</city> <state>NC</state> <zip>34829</zip> </inside-address> </letter> <!-- This is the Style sheet, normally it would require an XML header --> <!-- But later that it will concatenated to the beginning --> <!--================================================================--> <!-- Root Element Template --> <!-- This template specifies what creates the root element of the --> <!-- result tree. In this case, it tells the XSL processor to --> <!-- start with the <letter> element. --> <!--================================================================--> <xsl:template match="xsl:stylesheet"> <xsl:apply-templates select="icon:letter"/> </xsl:template> <!--================================================================--> <!-- <letter> template --> <!-- This template takes the letter element and processes its --> <!-- contents. --> <!--================================================================--> <xsl:template match="icon:letter"> <!--================================================================--> <!-- Cocoon processing instruction --> <!-- This processing instruction lets us serve an XML document as a --> <!-- PDF. The Cocoon servlet uses this instruction to invoke FOP --> <!-- automatically. --> <!--================================================================--> <xsl:processing-instruction name="cocoon-format">type="text/xslfo"</xsl:processing-instruction> <!--================================================================--> <!-- The fo:root element contains the entire document. --> <!--================================================================--> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <!--================================================================--> <!-- The layout-master-set defines a set of page layouts. For our --> <!-- purposes here, we only need one. --> <!--================================================================--> <fo:layout-master-set> <fo:simple-page-master master-name="main" page-width="21.0cm" page-height="29.7cm" margin-top="75pt" margin-bottom="75pt" margin-left="75pt" margin-right="75pt"> <!--================================================================--> <!-- The region-body element is where all the action is. We'll put --> <!-- all of our content into this space. --> <!--================================================================--> <fo:region-body margin-bottom="75pt"/> </fo:simple-page-master> </fo:layout-master-set> <!--================================================================--> <!-- Our next step is to define the page styles used. We can --> <!-- different page styles for the first page, odd pages, and even --> <!-- pages. They're all the same for this simple document. --> <!--================================================================--> <fo:page-sequence master-reference="main"> <fo:sequence-specification> <fo:sequence-specifier-alternating page-master-first="main" page-master-odd="main" page-master-even="main"/> </fo:sequence-specification> <!--================================================================--> <!-- Finally, we'll put everything into a flow element. --> <!--================================================================--> <fo:flow> <!--================================================================--> <!-- To get the formatting we want, we'll put the indented parts of --> <!-- the letter into a table. We used this same approach when we --> <!-- transformed the letter into HTML. The table columns help us --> <!-- align items as if we used tab stops in a word processor. --> <!--================================================================--> <fo:table space-before="6pt"> <fo:table-column column-width="225pt"/> <fo:table-column column-width="250pt"/> <fo:table-body> <fo:table-row space-before="3pt"> <!--================================================================--> <!-- We write the company and return address information into a --> <!-- single table cell. Notice that we have a blank table cell --> <!-- next to it. --> <!--================================================================--> <fo:table-cell> <fo:block> </fo:block> </fo:table-cell> <fo:table-cell> <xsl:apply-templates select="icon:company"/> <xsl:apply-templates select="icon:return-address"/> </fo:table-cell> </fo:table-row> <!--================================================================--> <!-- Now we write the date of the letter. We put this in a --> <!-- different table row so there will be some vertical space --> <!-- between them. --> <!--================================================================--> <fo:table-row space-before="3pt"> <fo:table-cell> <fo:block> </fo:block> </fo:table-cell> <fo:table-cell> <xsl:apply-templates select="icon:date"/> </fo:table-cell> </fo:table-row> </fo:table-body> </fo:table> <!--================================================================--> <!-- Now that we've written the indented parts of the letter, we'll --> <!-- write out the various pieces of text that are left-aligned. --> <!--================================================================--> <xsl:apply-templates select="icon:inside-address"/> <xsl:apply-templates select="icon:subject"/> <xsl:apply-templates select="icon:attention"/> <xsl:apply-templates select="icon:salutation"/> <xsl:apply-templates select="icon:body"/> <!--================================================================--> <!-- Now it's time for the closing and signature lines. These are --> <!-- indented as well, so we use another table. --> <!--================================================================--> <fo:table space-before="6pt"> <fo:table-column column-width="225pt"/> <fo:table-column column-width="250pt"/> <fo:table-body> <fo:table-row space-before="3pt"> <fo:table-cell/> <fo:table-cell> <xsl:apply-templates select="icon:closing"/> </fo:table-cell> </fo:table-row> <fo:table-row space-before="3pt"> <fo:table-cell/> <fo:table-cell> <xsl:apply-templates select="icon:signature"/> </fo:table-cell> </fo:table-row> </fo:table-body> </fo:table> <!--================================================================--> <!-- The last things that might be in the letter are some notes at --> <!-- the bottom. These are all left-aligned, so we put them --> <!-- outside the table. --> <!--================================================================--> <xsl:apply-templates select="icon:enclosure"/> <xsl:apply-templates select="icon:cc-list"/> <xsl:apply-templates select="icon:reference-initials"/> </fo:flow> </fo:page-sequence> </fo:root> </xsl:template> <!--================================================================--> <!-- Template for the <company> element. --> <!--================================================================--> <xsl:template match="icon:company"> <fo:block font-size="12pt" line-height="15pt" text-align="start"> <xsl:apply-templates/> </fo:block> </xsl:template> <!--================================================================--> <!-- Template for the <signature> element. --> <!--================================================================--> <xsl:template match="icon:signature"> <fo:block font-size="12pt" line-height="15pt" text-align="start" text-align-last="start"> <xsl:value-of select="icon:name/icon:first-name"/> <xsl:text> </xsl:text> <xsl:value-of select="icon:name/icon:last-name"/> </fo:block> <fo:block font-size="12pt" line-height="15pt" text-align="start" space-after="24pt"> <xsl:value-of select="icon:name/icon:job-title"/> </fo:block> </xsl:template> <!--================================================================--> <!-- <name> template --> <!-- This template processes the <name> element. If there is a --> <!-- <title>, we process it, followed by the <first-name> and --> <!-- <last-name> elements. --> <!--================================================================--> <xsl:template match="icon:name"> <fo:block font-size="12pt" line-height="15pt" text-align="start"> <xsl:apply-templates select="icon:title"/> <xsl:value-of select="icon:first-name"/> <xsl:text> </xsl:text> <xsl:value-of select="icon:last-name"/> </fo:block> </xsl:template> <!--================================================================--> <!-- <title> template --> <!-- This template processes the <title> tag. It returns the text --> <!-- of the <title> tag and a space. If no <title> tag exists, --> <!-- this template isn't called at all, so no unnecessary space is --> <!-- output. --> <!--================================================================--> <xsl:template match="icon:title"> <xsl:value-of select="."/> <xsl:text> </xsl:text> </xsl:template> <!--================================================================--> <!-- <body> template --> <!-- This template outputs each <para> element in an XSL:FO block --> <!-- element. --> <!--================================================================--> <xsl:template match="icon:body"> <xsl:for-each select="icon:para"> <fo:block font-size="12pt" line-height="15pt" text-align="start" space-after="12pt"> <xsl:value-of select="."/> </fo:block> </xsl:for-each> </xsl:template> <!--================================================================--> <!-- Template for the <salutation> element. --> <!--================================================================--> <xsl:template match="icon:salutation"> <fo:block font-size="12pt" line-height="15pt" text-align="start" space-after="12pt"> <xsl:value-of select="."/> <xsl:text>,</xsl:text> </fo:block> </xsl:template> <!--================================================================--> <!-- Template for the <closing> element. --> <!--================================================================--> <xsl:template match="icon:closing"> <fo:block font-size="12pt" line-height="15pt" text-align="start" space-after="48pt"> <xsl:value-of select="."/> <xsl:text>,</xsl:text> </fo:block> </xsl:template> <!--================================================================--> <!-- <return-address> template --> <!-- This template prints the various parts of a return address. --> <!--================================================================--> <xsl:template match="icon:return-address"> <fo:block font-size="12pt" line-height="15pt" text-align="start"> <xsl:value-of select="icon:street"/> </fo:block> <fo:block font-size="12pt" line-height="15pt" text-align="start" space-after="24pt"> <xsl:value-of select="icon:city"/> <xsl:text> </xsl:text> <xsl:value-of select="icon:state"/> <xsl:text>, </xsl:text> <xsl:value-of select="icon:zip"/> </fo:block> </xsl:template> <!--================================================================--> <!-- <inside-address> template --> <!-- This template prints the various parts of an inside address. --> <!-- It is different from the <return-address> template in that it --> <!-- processes a <name> element. --> <!--================================================================--> <xsl:template match="icon:inside-address"> <xsl:apply-templates select="icon:name"/> <fo:block font-size="12pt" line-height="15pt" text-align="start"> <xsl:value-of select="icon:street"/> </fo:block> <fo:block font-size="12pt" line-height="15pt" text-align="start" space-after="24pt"> <xsl:value-of select="icon:city"/> <xsl:text> </xsl:text> <xsl:value-of select="icon:state"/> <xsl:text>, </xsl:text> <xsl:value-of select="icon:zip"/> </fo:block> </xsl:template> <!--================================================================--> <!-- <enclosure> template --> <!-- This template prints the contents of any <enclosure> tag. --> <!--================================================================--> <xsl:template match="icon:enclosure"> <fo:block font-size="12pt" line-height="15pt" text-align="start" space-after="24pt"> <xsl:text>Enclosure: </xsl:text> <xsl:value-of select="."/> </fo:block> </xsl:template> <!--================================================================--> <!-- <cc-list> template --> <!-- This template prints the contents of the <cc-list> tag. Each --> <!-- <name> in the list is written to the output stream. --> <!--================================================================--> <xsl:template match="icon:cc-list"> <xsl:for-each select="icon:name"> <fo:block font-size="12pt" line-height="15pt" text-align="start"> <xsl:text>cc: </xsl:text> <xsl:value-of select="icon:first-name"/> <xsl:text> </xsl:text> <xsl:value-of select="icon:last-name"/> </fo:block> </xsl:for-each> </xsl:template> <!--================================================================--> <!-- <reference-initials> template --> <!-- This template prints the contents of the <reference-initials> --> <!-- tag. --> <!--================================================================--> <xsl:template match="icon:reference-initials"> <fo:block font-size="12pt" line-height="15pt" text-align="center"> <xsl:value-of select="."/> </fo:block> </xsl:template> <!--================================================================--> <!-- <date> template --> <!-- This template prints the date in month, day, year format. --> <!--================================================================--> <xsl:template match="icon:date"> <fo:block font-size="12pt" line-height="15pt" text-align="start" space-after="24pt"> <xsl:value-of select="@month"/> <xsl:text> </xsl:text> <xsl:value-of select="@day"/> <xsl:text>, </xsl:text> <xsl:value-of select="@year"/> </fo:block> </xsl:template> <!--================================================================--> <!-- <subject> template --> <!-- This template prints the word "Subject: ", followed by the --> <!-- text of the <subject> tag. --> <!--================================================================--> <xsl:template match="icon:subject"> <fo:block font-size="12pt" line-height="15pt" text-align="start" space-after="24pt"> <xsl:text>Subject: </xsl:text> <fo:wrapper font-weight="bold"> <xsl:value-of select="."/> </fo:wrapper> </fo:block> </xsl:template> <!--================================================================--> <!-- <attention> template --> <!-- This template prints the word "Attention: ", followed by the --> <!-- text of the <attention> tag. --> <!--================================================================--> <xsl:template match="icon:attention"> <fo:block font-size="12pt" line-height="15pt" text-align="start"> <xsl:text>Attention: </xsl:text> <xsl:value-of select="."/> </fo:block> </xsl:template> </xsl:stylesheet> -----Ursprüngliche Nachricht----- Von: Kaarle Kaila [mailto:kaarle.kaila@xxxxxx] Gesendet: Sonntag, 1. Februar 2004 12:22 An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Betreff: Embedded stylesheets hi, I have tried to use an embedded xslt stylesheet according to example in Michael Kays XSLT Programmers Reference 2nd edition on page 109 but it does not seem to work as desired by me. Extract of my xml-file is at end of message. If I look at the result with IE 6 it shows the headers OK but it also all other text (with default template). I tried to translate it using XMLStarlert (http://xmlstar.sourceforge.net/) that complained xml-stylesheet : no ID backup found My question is: should this way of using embedded stylesheets work or is it very much dependent on spaciel features of various xslt engines? regards Kaarle -- Kaarle Kaila email: kaarle dot kaila at iki dot fi www.iki.fi/kaila <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="#backup"?> <genealog><owner><ownername>Kaarle Kaila</ownername><ownerinfo>Kallen lisätietoa Tämä tulee riville 2 ja tässä näin riville 3 (Cyrillic text)?????? ???????? on rivillä 4</ownerinfo><address><street>Kalenteritie 23 B 4</street><postalcode>02200</postalcode><postoffice>Espoo</postoffice><count ry>Suomi</country> <email>kaarle.kaila@xxxxxx</email></address><mediapath>Kaila</mediapath></ow ner> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" id="backup"> <xsl:template match="xsl:sylesheet"/><xsl:template match="genealog"><html><body><h1>suku-backup</h1><xsl:apply-templates/></bod y></html></xsl:template><xsl:template match="units"><xsl:apply-templates/></xsl:template><xsl:template match="unit"><xsl:value-of select="./name"/><br/></xsl:template></xsl:stylesheet> <units> <unit unitid="I1" tag="INDI" sex="F" createdate="2004-01-16"><name><givenname>Liisa Annikki</givenname><surname>Koski</surname></name><notices><notice tag="NAME" row="1" createdate="2004-01-16"><name><givenname>Liisa Annikki</givenname><surname>Kaila</surname></name></notice> <notice tag="BIRT" row="2" createdate="2004-01-16"> <date><start>19180929</start></date><place>Hämeenkyrö</place><name/></notice > <notice tag="DEAT" row="3" createdate="2004-01-16"> <date><start>19880531</start></date><place>Espoo</place><name/></notice> <notice tag="OCCU" row="4" createdate="2004-01-16"><description>Vaatesuunnittelija</description><name/> </notice></notices></unit> <!-- more unit elements --> </units> <!-- other elements --> </genealog> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|