繁体   English   中英

从xsl:fo产生html xslt

[英]Producing html xslt from xsl:fo

我正在尝试将xsl:fo转换为xslt (用于HTML输出)。 然后,我将应用xslt而不是xsl:fo获得HTML输出而不是PDF。

怎么办

我需要用于XML处理的API,或者需要将XML和XSL转换为另一个输出的JAXP。 因此,我尝试编写xslt模板:

<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>

我得到类似的东西

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

但是它会删除所有xsl:choose xsl:when和其他标签,例如我需要所有这些标签,因为我需要使用Jaxp在第二遍传递xml数据并生成html。

        <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>

如何获得XSL节点(如文本节点)?

如果要使用XSLT输出XSLT元素(即XSLT名称空间中的元素),则需要使用名称空间别名,如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>

我把xsl:代码之间<! CDATA [...]]>

无论如何使用另一个名称空间

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM