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

applying diff styles/formatting to an xml element in diff parts of XMLDoc:HOWTO

Expand Messages
  • abhisheksanwal
    How is it possible to apply different styles/formatting to an xml element in different parts of the XML document for a resulting FO document. For e.g. I have
    Message 1 of 4 , Aug 3, 2003
    • 0 Attachment
      How is it possible to apply different styles/formatting to an xml
      element in different parts of the XML document for a resulting FO
      document.

      For e.g. I have an element i.e. say - <SectionHeading>

      Now of course the XSL Template that matches this element will apply
      to the element.

      How would it be possible to define different FO
      style/block/layout/spacing to the XML elements of the same name in
      different parts of the FO document that is to be created. (Eventually
      to PDF).

      I know that one way would be to change the XML element tag names to
      something else and apply templates based on that.

      But we want to MAINTAIN the documents "content" model. But want to be
      able to apply varied types of styling by editing the XSLs.

      One way I was thinking was to apply "modes" but that would mean that
      I would have to add "modes" to the XML document.

      Another one I was thinking was some kind of COUNT (like in a
      programming language) where elements whose counts are within
      different ranges are worked on by different formatting/layout blocks.
      Of course my stylesheets would get really complicated.

      Can someone suggest some ideas for this WITHOUT any changes to the
      XML data and element model.

      Please do let me know or point me to a tutorial/reference to do this
      without complicating my stylesheet and life a lot.

      Thanks in advance.

      Abhishek Sanwal
    • Elizabeth Barham
      Hi Abhishek ... You can define matches based on an element s parent(s) and the transformer should use the most specific match:
      Message 2 of 4 , Aug 3, 2003
      • 0 Attachment
        Hi Abhishek

        "abhishek" writes:

        > How is it possible to apply different styles/formatting to an xml
        > element in different parts of the XML document for a resulting FO
        > document.
        >
        > For e.g. I have an element i.e. say - <SectionHeading>
        >
        > Now of course the XSL Template that matches this element will apply
        > to the element.

        You can define matches based on an element's parent(s) and the
        transformer should use the most specific match:

        <xsl:template match="intro/SectionHeader"/>

        versus

        <xsl:template match="SectionHeader"/>

        etc.


        > How would it be possible to define different FO
        > style/block/layout/spacing to the XML elements of the same name in
        > different parts of the FO document that is to be
        > created. (Eventually to PDF).
        >
        > I know that one way would be to change the XML element tag names to
        > something else and apply templates based on that.
        >
        > But we want to MAINTAIN the documents "content" model. But want to
        > be able to apply varied types of styling by editing the XSLs.
        >
        > One way I was thinking was to apply "modes" but that would mean that
        > I would have to add "modes" to the XML document.
        >
        > Another one I was thinking was some kind of COUNT (like in a
        > programming language) where elements whose counts are within
        > different ranges are worked on by different formatting/layout
        > blocks. Of course my stylesheets would get really complicated.
        >
        > Can someone suggest some ideas for this WITHOUT any changes to the
        > XML data and element model.
        >
        > Please do let me know or point me to a tutorial/reference to do this
        > without complicating my stylesheet and life a lot.

        I suppose that if the elements are siblings, you could use your count
        method along the lines of:

        <xsl:template match="SectionHeader">
        <xsl:choose>
        <xsl:when test="count(preceding-sibling::SectionHeader) < 12">
        <xsl:apply-templates select="." mode="beginning-of-document"/>
        </xsl:when>
        <xsl:otherwise>
        <xsl:apply-templates select="." mode="not-at-beginning-of-document"/>
        </xsl:otherwise>
        </xsl:choose>
        </xsl:template>

        <xsl:template match="SectionHeader" mode="beginning-of-document"/>
        <xsl:template match="SectionHeader" mode="not-at-beginning-of-document"/>

        hth, Elizabeth
      • abhisheksanwal
        ... apply ... to ... that ... this ... I suppose that if the elements are siblings, you could use your count method along the lines of:
        Message 3 of 4 , Aug 4, 2003
        • 0 Attachment
          --- In XSL-FO@yahoogroups.com, Elizabeth Barham <lizzy@s...> wrote:
          > Hi Abhishek
          >
          > "abhishek" writes:
          >
          > > How is it possible to apply different styles/formatting to an xml
          > > element in different parts of the XML document for a resulting FO
          > > document.
          > >
          > > For e.g. I have an element i.e. say - <SectionHeading>
          > >
          > > Now of course the XSL Template that matches this element will
          apply
          > > to the element.
          >
          > You can define matches based on an element's parent(s) and the
          > transformer should use the most specific match:
          >
          > <xsl:template match="intro/SectionHeader"/>
          >
          > versus
          >
          > <xsl:template match="SectionHeader"/>
          >
          > etc.
          >
          >
          > > How would it be possible to define different FO
          > > style/block/layout/spacing to the XML elements of the same name in
          > > different parts of the FO document that is to be
          > > created. (Eventually to PDF).
          > >
          > > I know that one way would be to change the XML element tag names
          to
          > > something else and apply templates based on that.
          > >
          > > But we want to MAINTAIN the documents "content" model. But want to
          > > be able to apply varied types of styling by editing the XSLs.
          > >
          > > One way I was thinking was to apply "modes" but that would mean
          that
          > > I would have to add "modes" to the XML document.
          > >
          > > Another one I was thinking was some kind of COUNT (like in a
          > > programming language) where elements whose counts are within
          > > different ranges are worked on by different formatting/layout
          > > blocks. Of course my stylesheets would get really complicated.
          > >
          > > Can someone suggest some ideas for this WITHOUT any changes to the
          > > XML data and element model.
          > >
          > > Please do let me know or point me to a tutorial/reference to do
          this
          > > without complicating my stylesheet and life a lot.

          I suppose that if the elements are siblings, you could use your
          count method along the lines of:

          <xsl:template match="SectionHeader">
          <xsl:choose>
          <xsl:when test="count(preceding-sibling::SectionHeader) <12">
          <xsl:apply-templates select="." mode="beginning-of-document"/>
          </xsl:when>
          <xsl:otherwise>
          <xsl:apply-templates select="." mode="not-at-beginning-of-
          document"/>
          </xsl:otherwise>
          </xsl:choose>
          </xsl:template>

          <xsl:template match="SectionHeader" mode="beginning-of-document"/>
          <xsl:template match="SectionHeader" mode="not-at-beginning-of-
          document"/>

          hth, Elizabeth
          ---------------------------------------------
          BUT,

          What if the parent element was also the same ?

          Now what I have as the key difference is that an ATTRIBUTE of the
          parent element is specific STRING.

          How could I used that specific attribute as the flag/selector to
          apply different formatting to that child element.
        • Chris Bowditch
          ... ... You can use the xsl:choose element within your template, e.g. (you didnt say what the name of your attribute is that determines the formatting
          Message 4 of 4 , Aug 5, 2003
          • 0 Attachment
            >From: "abhisheksanwal" <abhisheksanwal@...>

            <snip/>

            >Now what I have as the key difference is that an ATTRIBUTE of the
            >parent element is specific STRING.
            >
            >How could I used that specific attribute as the flag/selector to
            >apply different formatting to that child element.
            >

            You can use the xsl:choose element within your template, e.g.

            (you didnt say what the name of your attribute is that determines the
            formatting to be applied to the SectionHeader element, so Ive assumed its
            called style below)


            <xsl:template match="SectionHeader">
            <xsl:choose>
            <xsl:when test="@style='style1'">
            <!-- put your FO for style1 here -->
            </xsl:when>
            <xsl:when test="@style='style2'">
            <!-- put your FO for style2 here -->
            </xsl:when>
            <xsl:otherwise>
            <!-- put your default FO (with no style) here -->
            </xsl:otherwise>
            </xsl:choose>
            </xsl:template>

            _________________________________________________________________
            Find a cheaper internet access deal - choose one to suit you.
            http://www.msn.co.uk/internetaccess
          Your message has been successfully submitted and would be delivered to recipients shortly.