好像发现这两天有人试图批量下载 >>
<< 用XSLT生成FO Tree的代码片断
Transform bookmarks of FOP's FOX into HTML

Author Zhou Renjian Create@ 2005-08-09 11:22
whizz Note icon
<?xml version='1.0' encoding='gb18030'?>
<!--
  - author: Jozz (mailto:zhourj@primeton.com)
  -->

<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:fox="http://xml.apache.org/fop/extensions"
                xmlns:fn="http://www.w3.org/2004/07/xpath-functions"
                exclude-result-prefixes="#all"
                >
                

<xsl:output method="html"
            version="4.0"
            indent="no"/>
            
<!--<xsl:output method="xml" version="1.0" encoding="GB2312" indent="yes"/>-->
 
<xsl:variable name="expand-level">3</xsl:variable>
<xsl:variable name="images-base">../images</xsl:variable>
 
<xsl:template match="/">
  <html>
    <head>
      <style type="text/css">
        a {
          text-decoration:none;
          color:black;
          cursor:default;
        }
        pre {
          margin: 0;
          padding: 0;
          line-height: 1em;
          font-family: Arial;
          font-size: 12pt;
        }
        body {
          background-color: white;
          padding:0;
          margin:0;
          padding-top:4px;
          padding-bottom:4px;
          padding-right:4px;
        }
      </style>
      <script type="text/javascript">
        <![CDATA[
/**
 * @author zhourj@primeton.com
 */
function toggle(o) {
    if (o == null) {
        return;
    }
    var isExpanded = false;
    if (o.src != null && o.src.length != 0) {
        if (o.src.indexOf("minus") != -1) {
            isExpanded = true;
            o.src = o.src.replace("minus", "plus");
        } else {
            isExpanded = false;
            o.src = o.src.replace("plus", "minus");
        }
    } else {
        var items = o.parentNode.childNodes;
        for (var i = 0; i < items.length; i++) {
            var item = items.item(i);
            if (item.nodeName == "IMG" && item.src != null
                    && item.src.length != 0
                    && (item.src.indexOf("minus") != -1
                    || item.src.indexOf("plus") != -1)) {
                if (item.src.indexOf("minus") != -1) {
                    isExpanded = true;
                    item.src = item.src.replace("minus", "plus");
                } else {
                    isExpanded = false;
                    item.src = item.src.replace("plus", "minus");
                }
                break;
            }
        }
    }
    var items = o.parentNode.parentNode.childNodes;
    for (var i = 0; i < items.length; i++) {
        var item = items.item(i);
        if (item.nodeName == "DIV") {
            if (isExpanded) {
                item.style.display = "none";
            } else {
                item.style.display = "";
            }
        }
    }
}
        ]]>
      </script>
    </head>
    <body>
  <xsl:apply-templates select="/fo:root/fox:outline"/>
    </body>
  </html>
</xsl:template>

<xsl:template match="fox:outline">
  <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, ':')"/>
  <div>
    <xsl:variable name="item-count" select="count(fox:outline)"/>
    <xsl:variable name="hiers-count" select="count($hierarchies)"/>
    <xsl:if test="$hiers-count &gt; $expand-level">
      <xsl:attribute name="style">display:none;</xsl:attribute>
    </xsl:if>
    <xsl:comment>PRE is used to keep the item in one line.</xsl:comment>
    <pre>
    <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 &gt; 0">
                  <xsl:choose>
                    <xsl:when test="$hiers-count &gt;= $expand-level">
                      <img src="{$images-base}/Tplus.png">
                        <xsl:call-template name="image-node-attrs"/>
                      </img>
                    </xsl:when>
                    <xsl:otherwise>
                      <img src="{$images-base}/Tminus.png">
                        <xsl:call-template name="image-node-attrs"/>
                      </img>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <img src="{$images-base}/T.png">
                    <xsl:call-template name="image-common-atts"/>
                  </img>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <img src="{$images-base}/I.png">
                <xsl:call-template name="image-common-atts"/>
              </img>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="position() = $hiers-count">
              <xsl:choose>
                <xsl:when test="$item-count &gt; 0">
                  <xsl:choose>
                    <xsl:when test="$hiers-count &gt;= $expand-level">
                      <img src="{$images-base}/Lplus.png">
                        <xsl:call-template name="image-node-attrs"/>
                      </img>
                    </xsl:when>
                    <xsl:otherwise>
                      <img src="{$images-base}/Lminus.png">
                        <xsl:call-template name="image-node-attrs"/>
                      </img>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$hiers-count = 1">
                  <img src="{$images-base}/blank.png">
                    <xsl:call-template name="image-common-atts"/>
                  </img>
                </xsl:when>
                <xsl:otherwise>
                  <img src="{$images-base}/L.png">
                    <xsl:call-template name="image-common-atts"/>
                  </img>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <img src="{$images-base}/blank.png">
                <xsl:call-template name="image-common-atts"/>
              </img>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
    <img src="{$images-base}/file.png">
      <xsl:call-template name="image-icon-atts"/>
      <xsl:attribute name="ondblclick">javascript:toggle(this);</xsl:attribute>
    </img>
    <xsl:element name="a">
      <xsl:attribute name="href">
        <xsl:value-of select="concat(@internal-destination, '.html')"/>
      </xsl:attribute>
      <xsl:attribute name="target">htmls</xsl:attribute>
      <xsl:attribute name="ondblclick">javascript:toggle(this);</xsl:attribute>
      <xsl:value-of select="fox:label"/>
    </xsl:element>
    </pre>
    <xsl:for-each select="fox:outline">
      <xsl:apply-templates select=".">
        <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>
  </div>
</xsl:template>
 
<xsl:template name="image-common-atts">
  <xsl:attribute name="width">19</xsl:attribute>
  <xsl:attribute name="height">16</xsl:attribute>
  <xsl:attribute name="alt">x</xsl:attribute>
</xsl:template>
 
<xsl:template name="image-icon-atts">
  <xsl:attribute name="width">16</xsl:attribute>
  <xsl:attribute name="height">16</xsl:attribute>
  <xsl:attribute name="alt">x</xsl:attribute>
  <xsl:attribute name="style">margin-left:2px;margin-right:2px;</xsl:attribute>
</xsl:template>

<xsl:template name="image-node-attrs">
  <xsl:call-template name="image-common-atts"/>
  <xsl:attribute name="onclick">javascript:toggle(this);</xsl:attribute>
</xsl:template>
 
</xsl:stylesheet>

本记录所在类别:
本记录相关记录: