robyp7
robyp7

Reputation: 491

Producing html xslt from xsl:fo

I'm tring to transform an xsl:fo into xslt (for HTML output). Then, I would apply xslt instead of xsl:fo obtaining the HTML output instead of a PDF.

How can do this?

I need API for XML Processing, or JAXP that transforms XML and XSL to another output. So, I tried to write the xslt template:

<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" exclude-result-prefixes="fo"
>

<xsl:template match="/xsl:template[@match='/root']/fo:root">
 <xsl:apply-templates select="fo:page-sequence"/>
</xsl:template>

 <xsl:template match="fo:page-sequence">

<xsl:for-each select="fo:flow[@flow-name='xsl-region-body']">
    <xsl:call-template name="xsl-regional-body">
            <xsl:with-param name="fontsize"><xsl:value-of select="@font-size"/></xsl:with-param>
        </xsl:call-template>
    </xsl:for-each>
</xsl:template>

<xsl:template name="xsl-regional-body">
    <xsl:param name="fontsize" />
    <body>      
        <xsl:if test="$fontsize"> <!-- costruisce <font size=""> -->
            <font>
            <xsl:attribute name="size">
                <xsl:value-of select="$fontsize"/>
            </xsl:attribute> 
            </font>
        </xsl:if>
        <xsl:for-each select="*/xsl:choose">
                <xsl:call-template name="xsl-choose"/>
        </xsl:for-each>
        <xsl:apply-templates select="."/>
    </body>
</xsl:template>

<xsl:template name="xsl-choose">
    <xsl:value-of select="."/>
</xsl:template>

I obtain something like

        <body><font size="10pt"/>
         ...
         text words..
        </body>

But it delete all xsl:choose xsl:when and other tags like I need all these tags because i need to pass xml data in second pass using Jaxp and producing html.. I would obtain

        <body><font size="10pt"/>
         <xsl:choose>
         <xsl:when test="ddx[@id='LET.....>
            <xsl::value-of select="ddx[@id='Lx']/r/PE...>
         </xsl:when>..
         </xsl:choose>
         text words..
        </body>

How can get the XSL nodes like text node?

Upvotes: 0

Views: 355

Answers (2)

robyp7
robyp7

Reputation: 491

i put xsl: code between < ! CDATA [... ] ] >

anyway using another namespace

Upvotes: 0

Martin Honnen
Martin Honnen

Reputation: 167401

If you want to use XSLT to output XSLT elements (i.e. elements in the XSLT namespace) then you need to use a namespace alias as shown in http://www.w3.org/TR/xslt#literal-result-element:

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

<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>

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

<xsl:template match="block">
  <axsl:template match="{.}">
     <fo:block><axsl:apply-templates/></fo:block>
  </axsl:template>
</xsl:template>

</xsl:stylesheet>

Upvotes: 1

Related Questions