用XSLT生成FO Tree的代码片断
Author
Zhou Renjian
Create@
2005-08-09 11:17
<xsl:variable name="expand-level">30</xsl:variable>
<xsl:variable name="images-base">images</xsl:variable>
<xsl:template name="image-common-atts">
<xsl:attribute name="width">
<xsl:value-of select="eos:convert-px-cm(19)"/>
<xsl:value-of select="'cm'"/>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="eos:convert-px-cm(16)"/>
<xsl:value-of select="'cm'"/>
</xsl:attribute>
</xsl:template>
<xsl:template name="image-icon-atts">
<xsl:attribute name="width">
<xsl:value-of select="eos:convert-px-cm(16)"/>
<xsl:value-of select="'cm'"/>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="eos:convert-px-cm(16)"/>
<xsl:value-of select="'cm'"/>
</xsl:attribute>
</xsl:template>
<xsl:template name="image-node-attrs">
<xsl:call-template name="image-common-atts"/>
</xsl:template>
<xsl:template match="EOSDataTree|EOSDataNode|EOSEntityNode|EOSFieldNode" mode="ui-tree">
<xsl:param name="dep-str"/>
<xsl:variable name="indepth">
<xsl:choose>
<xsl:when test="$dep-str">
<xsl:value-of select="string-length($dep-str)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="in-dep-str">
<xsl:choose>
<xsl:when test="$dep-str">
<xsl:value-of select="$dep-str"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'0'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="hierarchies" select="tokenize($in-dep-str, ':')"/>
<fo:block>
<xsl:variable name="item-count" select="count(EOSDataNode|EOSEntityNode|EOSFieldNode)"/>
<xsl:variable name="hiers-count" select="count($hierarchies)"/>
<xsl:for-each select="$hierarchies">
<xsl:choose>
<xsl:when test=". = '1'">
<xsl:choose>
<xsl:when test="position() = $hiers-count">
<xsl:choose>
<xsl:when test="$item-count > 0">
<xsl:choose>
<xsl:when test="$hiers-count >= $expand-level">
<fo:external-graphic src="{$images-base}/Tplus.png">
<xsl:call-template name="image-node-attrs"/>
</fo:external-graphic>
</xsl:when>
<xsl:otherwise>
<fo:external-graphic src="{$images-base}/Tminus.png">
<xsl:call-template name="image-node-attrs"/>
</fo:external-graphic>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<fo:external-graphic src="{$images-base}/T.png">
<xsl:call-template name="image-common-atts"/>
</fo:external-graphic>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<fo:external-graphic src="{$images-base}/I.png">
<xsl:call-template name="image-common-atts"/>
</fo:external-graphic>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="position() = $hiers-count">
<xsl:choose>
<xsl:when test="$item-count > 0">
<xsl:choose>
<xsl:when test="$hiers-count >= $expand-level">
<fo:external-graphic src="{$images-base}/Lplus.png">
<xsl:call-template name="image-node-attrs"/>
</fo:external-graphic>
</xsl:when>
<xsl:otherwise>
<fo:external-graphic src="{$images-base}/Lminus.png">
<xsl:call-template name="image-node-attrs"/>
</fo:external-graphic>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$hiers-count = 1">
<fo:external-graphic src="{$images-base}/blank.png">
<xsl:call-template name="image-common-atts"/>
</fo:external-graphic>
</xsl:when>
<xsl:otherwise>
<fo:external-graphic src="{$images-base}/L.png">
<xsl:call-template name="image-common-atts"/>
</fo:external-graphic>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<fo:external-graphic src="{$images-base}/blank.png">
<xsl:call-template name="image-common-atts"/>
</fo:external-graphic>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<fo:external-graphic space-end="2pt" margin-right="2pt">
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="@referName">
<xsl:value-of select="concat($images-base, '/datatree_file.gif')"/>
</xsl:when>
<xsl:when test="@type='isTable'">
<xsl:value-of select="concat($images-base, '/datatable_file.gif')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($images-base, '/datatree_node.gif')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:call-template name="image-icon-atts"/>
</fo:external-graphic>
<xsl:call-template name="common-inline">
<xsl:with-param name="text-str">
<xsl:choose>
<xsl:when test="@referName">
<xsl:value-of select="@referName"/>
</xsl:when>
<xsl:when test="@fieldName">
<xsl:value-of select="@fieldName"/>
</xsl:when>
<xsl:when test="@type='isTable'">
<xsl:value-of select="eos:get-data-name(@link)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
<xsl:for-each select="EOSDataNode|EOSFieldNode|EOSEntityNode">
<xsl:apply-templates select="." mode="ui-tree">
<xsl:with-param name="dep-str">
<xsl:value-of select="$in-dep-str"/>
<xsl:choose>
<xsl:when test="position() = $item-count">:0</xsl:when>
<xsl:otherwise>:1</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:apply-templates>
</xsl:for-each>
</fo:block>
</xsl:template>