Re: [xsl] question on line breaks / chess

Subject: Re: [xsl] question on line breaks / chess
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 17 Jul 2009 07:36:10 -0400
At 2009-07-17 05:55 +0200, Hermann Stamm-Wilbrandt wrote:
Now I have three questions:
1) How can I inspect the output of the transformation in the browser?
   "View source" does not help since it shows the XML input.

If you are using IE then you can run the IE DLL from the command line using a tool I posted January 2001 based on discussions on this list:


http://www.CraneSoftwrights.com/resources/debugmsxml

... just scrape the 14-line script and five-line batch file.

2) How can I make the output of the browser transformation similar to
   that of xsltproc?

   board.html looks like this, all in a single line (split into many
   lines here for readybility, only):

That sounds like an <xsl:output indent="no"/> would address the problem, but you don't give many (any!) clues as to what is actually wrong, so I'm not sure how you can ask us to tell you how to fix it.


   <html><table border="1"><tr><td><img src="gif/brw.gif"><img src="gif/
   bnb.gif"><img src="gif/bbw.gif"><img src="gif/bqb.gif"><img src="gif/
   bkw.gif"><img src="gif/bbb.gif"><img src="gif/bnw.gif"><img src="gif/
   brb.gif"><br><img src="gif/bpb.gif">...
   ...<img src="gif/wrw.gif"><br></td></tr></table></html>

3) Is there a better way than having template matching "f" with mode in
   order to handle field background color appropriately?

I am guessing you are not aware of a basic facility in XSLT that <xsl:apply-templates/> is allowed to pass parameters.


This is your code:

  ...
  <xsl:template match="row">
    <xsl:choose>
      <xsl:when test="(position() mod 2)=0">
        <xsl:apply-templates select="f" mode="w"/><br/>?
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="f" mode="b"/><br/>?
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="f" mode="w">
    <xsl:call-template name="img">>
      <xsl:with-param name="pos" select="position()+0"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="f" mode="b">
    <xsl:call-template name="img">>
      <xsl:with-param name="pos" select="position()+1"/>
    </xsl:call-template>
  </xsl:template>
  ...

Without testing, I think your code above reduces to:


  <xsl:template match="row">
    <xsl:apply-templates select="f">
      <xsl:with-param name="rowOffset" select="position() mod 2"/>
    </xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="f" name="img">
    <xsl:param name="rowOffset"/>
    <xsl:variable name="pos" select="position() + $rowOffset"/>
    ... img template stuff ...
  </xsl:template>

I hope this helps.

. . . . . . . . . . . Ken

--
XSLT/XSL-FO/XQuery hands-on training - Oakland, CA, USA 2009-08-03
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread