Loading ...
Sorry, an error occurred while loading the content.

Re: XSL transformation question

Expand Messages
  • Jim
    Hi, Yes, your style sheet is working. Thanks. However, (and I did not define this in my question) the style sheet is dependant on the STYLE element
    Message 1 of 4 , Mar 27, 2003
    • 0 Attachment
      Hi,

      Yes, your style sheet is working. Thanks. However, (and I did not
      define this in my question) the style sheet is dependant on the STYLE
      element containing a FONT-BOLD element. If the STYLE element
      doesn't - no text is rendered in the XSL-FO.

      I am making progress on this....I came up with a style sheet that
      allows for a the style element to be present or not, and even new
      elements to be defined, such as italic. I included it below. Notice
      that it will render the TEXT element in any case. If a STYLE element
      exists, those styles will be applied to the text in the TEXT
      element. It seems to work okay so far...

      Thank you for your help. I came up with my solution after I studied
      your style sheet!

      -Jim



      <!-- START XML -->

      <DOCUMENT>
      <CONTENT>
      <STYLE>
      <FONT-BOLD />
      <FONT-ITALIC />
      </STYLE>
      <TEXT>
      Hello World
      </TEXT>
      </CONTENT>
      </DOCUMENT>

      <!-- END XML -->


      <!-- START XSL -->

      <?xml version="1.0"?>

      <xsl:stylesheet version="1.0"
      xmlns:fo="http://www.w3.org/1999/XSL/Format"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

      <xsl:output method="xml" version="1.0" encoding="utf-8" />

      <xsl:template match="/">
      <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
      <fo:simple-page-master master-name="all-pages">
      <fo:region-body region-name="xsl-region-body" margin="0.7in"
      column-gap="0.25in" border="0.25pt solid gray" padding="6pt"
      column-count="2"/>
      <fo:region-before region-name="xsl-region-before" extent="0.7in"
      display-align="after" padding="6pt 0.7in"/>
      <fo:region-after region-name="xsl-region-after" extent="0.7in"
      display-align="before" padding="6pt 0.7in"/>
      </fo:simple-page-master>
      <fo:page-sequence-master master-name="default-sequence">
      <fo:repeatable-page-master-reference master-reference="all-pages"/>
      </fo:page-sequence-master>
      </fo:layout-master-set>

      <fo:page-sequence master-reference="default-sequence">
      <fo:static-content flow-name="xsl-region-before">
      </fo:static-content>
      <fo:flow flow-name="xsl-region-body">
      <xsl:apply-templates select="DOCUMENT"/>
      </fo:flow>
      </fo:page-sequence>

      </fo:root>
      </xsl:template>

      <xsl:template match="DOCUMENT">
      <fo:block>
      <xsl:apply-templates select="CONTENT"/>
      </fo:block>
      </xsl:template>

      <xsl:template match="CONTENT">
      <fo:inline>
      <xsl:apply-templates select="STYLE/*" />
      <xsl:apply-templates />
      </fo:inline>
      </xsl:template>

      <xsl:template match="TEXT">
      <xsl:apply-templates />
      </xsl:template>

      <xsl:template match="FONT-BOLD">
      <xsl:attribute name="font-weight">bold</xsl:attribute>
      </xsl:template>

      <xsl:template match="FONT-ITALIC">
      <xsl:attribute name="font-style">italic</xsl:attribute>
      </xsl:template>

      </xsl:stylesheet>


      <!-- END XSL -->



      --- In XSL-FO@yahoogroups.com, AndrewWatt2001@a... wrote:
      > In a message dated 27/03/2003 19:28:15 GMT Standard Time,
      > Jim.Carbone@N... writes:
      >
      >
      > > Below are the documents. The XML and XSL each begin with a START
      > > comment and end with an "END" comment. These document DO
      generate
      > > valid XSL-FO.
      >
      > OK, from your earlier post that is what I expected.
      >
      > *** What I need to do is process a XML document that
      > > does not enclose the test "Hello World" with the formatting
      > > instructions. My XML document contains two elements in the
      CONTENT
      > > element. One is styling information (STYLE tag), the other is
      text
      > > (TEXT tag). This is defined as the first piece of XML in my
      previous
      > > post.
      > >
      > > So in other words, the XML/XSL documents below are how I
      typically
      > > think of processing, but my real world example doesn't allow me
      to
      > > solve the probelm as I normally would. I need a strategy to
      process
      > > the new scenario in my XSL to generate valid XSL-FO.
      >
      > Does the following give you the output you want?
      >
      > Andrew Watt
      >
      > <?xml version="1.0"?>
      >
      > <xsl:stylesheet version="1.0"
      > xmlns:fo="http://www.w3.org/1999/XSL/Format"
      > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      >
      > <xsl:output method="xml" version="1.0" encoding="utf-8" />
      >
      > <xsl:template match="/">
      > <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      > <fo:layout-master-set>
      > <fo:simple-page-master master-name="all-pages">
      > <fo:region-body region-name="xsl-region-body" margin="0.7in"
      > column-gap="0.25in" border="0.25pt solid gray" padding="6pt"
      > column-count="2"/>
      > <fo:region-before region-name="xsl-region-before" extent="0.7in"
      > display-align="after" padding="6pt 0.7in"/>
      > <fo:region-after region-name="xsl-region-after" extent="0.7in"
      > display-align="before" padding="6pt 0.7in"/>
      > </fo:simple-page-master>
      > <fo:page-sequence-master master-name="default-sequence">
      > <fo:repeatable-page-master-reference master-reference="all-
      pages"/>
      > </fo:page-sequence-master>
      > </fo:layout-master-set>
      >
      > <fo:page-sequence master-reference="default-sequence">
      > <fo:static-content flow-name="xsl-region-before">
      > </fo:static-content>
      > <fo:flow flow-name="xsl-region-body">
      > <xsl:apply-templates select="DOCUMENT"/>
      > </fo:flow>
      > </fo:page-sequence>
      >
      > </fo:root>
      > </xsl:template>
      >
      > <xsl:template match="DOCUMENT">
      > <fo:block>
      > <xsl:apply-templates select="CONTENT"/>
      > </fo:block>
      > </xsl:template>
      >
      > <xsl:template match="CONTENT">
      > <fo:block>
      > <xsl:apply-templates select="STYLE/FONT-BOLD"/>
      > </fo:block>
      > </xsl:template>
      >
      > <xsl:template match="TEXT">
      > <xsl:apply-templates />
      > </xsl:template>
      >
      > <xsl:template match="FONT-BOLD">
      > <fo:inline font-weight="bold">
      > <xsl:apply-templates select="/DOCUMENT/CONTENT/TEXT" />
      > </fo:inline>
      > </xsl:template>
      >
      > </xsl:stylesheet>
      >
      >
      > [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.