Hi,
I'm a FOP/XSL newbie, so please spell out any response. Thanks.
My problem is that I want to produce a PDF document from some XML. I'm using
FOP to do this and the problem I have may be XSL related, so my apologies if
this is the wrong forum to use. If an XSL forum is the place to go could you
please advise which one. I've already tried Dev Shed with no luck.
There may also be a better way for me to solve this problem, I'm sure !
My XML can contain optional attributes for tables, things like border-width,
border-style etc. I need to supply default values if the attribute does not
exist and as there could be many optional parameters I don't want to use
XSL:choose statements to cope with the variations.
Instead I'm trying to use a get_params template to see what parameter is in
question, return the value of the supplied attribute else the default which
is then used in a with_params statement. The code below is a cludge to try
and get it working for one attribute (border-style) only.
With the xml & code below I get the following error (from FOP) at the marked
location:
xsl:with-param is not allowed in this position in the stylesheet!
XML
<appendix-xml>
<table border-style="solid" col1="50%" col2="50%">
<row>
<cell><checkbox/> On site at a XX location using XX
approved equipment and local XX network</cell><cell><checkbox/> Non-XX
secure location, XX approved equipment, direct connection to XX network, no
direct connections to any other network</cell>
</row>
<row>
<cell><checkbox/> Remote VPN access to XX systems
for 3rd parties using non-XX PCs</cell><cell><checkbox/> VPN for XXX access
only</cell>
</row>
<row>
<cell><checkbox/> Citrix
access</cell><cell><checkbox/> Other: Please specify:</cell>
</row>
</table>
</appendix-xml>
XSL
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:variable name="border" select="'1pt'"/>
<xsl:variable name="border-style" select="'solid'"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-portrait"
page-height="29.7cm" page-width="21.0cm"
margin="2cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-portrait"
font-size="10pt">
<fo:flow flow-name="xsl-region-body">
<fo:block space-before="4mm">
<xsl:apply-templates
select="appendix-xml" />
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="appendix-xml">
<xsl:for-each select="node()">
<xsl:apply-templates select="." />
</xsl:for-each>
</xsl:template>
<xsl:template match="table">
<xsl:variable name="border"><xsl:value-of
select="@border"/></xsl:variable>
<xsl:variable name="border-style"><xsl:value-of
select="@border-style"/></xsl:variable>
<fo:table table-layout="fixed" width="100%"
border-style="{$border-style}" border-color="black"
border-width="{$border}">
<fo:table-column column-width="{...@col1}"/>
<fo:table-column column-width="{...@col2}"/>
<fo:table-body>
<xsl:for-each select="node()">
<xsl:apply-templates select=".">
<xsl:with-param
name="border-style" select="../@border-style"/>
</xsl:apply-templates>
</xsl:for-each>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="row">
<xsl:param name="border-style" select="'solid'"/>
<fo:table-row>
<xsl:for-each select="node()">
<xsl:apply-templates select=".">
<xsl:with-param name="border-style"
select="$border-style"/>
</xsl:apply-templates>
</xsl:for-each>
</fo:table-row>
</xsl:template>
<xsl:template match="cell">
<xsl:param name="border-style" select="'solid'"/>
<xsl:call-template name="output-cell-and-contents">
<!-- THIS BIT ONLY DOES NOT WORK -->
<xsl:with-param name="border-style">
<xsl:call-template name="get_param"/>
<xsl:with-param name="param"
select="$border-style"/>
</xsl:call-template>
</xsl:with-param>
<!-- ABOVE DOES NOT WORK -->
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="get_param">
<xsl:param name="param" select="'solid'"/>
<xsl:choose>
<xsl:when test="string-length($param)=0">
<xsl:text>solid</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$param"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="output-cell-and-contents">
<xsl:param name="border-style" select="'solid'"/>
<xsl:param name="node"/>
<fo:table-cell border-style="{$border-style}"
border-color="black" border-width="1">
<fo:block>
<xsl:for-each select="node()">
<xsl:apply-templates select="."/>
</xsl:for-each>
</fo:block>
</fo:table-cell>
</xsl:template>
<xsl:template match="checkbox">
<fo:inline border-style="solid" border-color="black"
background-color="#CCCCCC">
<xsl:text>***</xsl:text>
</fo:inline>
<xsl:text>***</xsl:text>
</xsl:template>
</xsl:stylesheet>
Thanks for your help.....
--
View this message in context:
http://www.nabble.com/Optional-XML-attributes---default-values-tp22499881p22499881.html
Sent from the FOP - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]