test.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="desired-thread">attribute</xsl:param>
<xsl:variable name="attributevalue">attribute</xsl:variable>
<xsl:template match="/">
<xsl:element name="tree">
   <xsl:apply-templates select="/table_att_pk_view"/>
</xsl:element>
</xsl:template><xsl:template match="namespace">
<xsl:variable name="namespaceid"><xsl:value-of select="namespace[@id]"></xsl:value-of></xsl:variable>
   <xsl:for-each select="tablename">
      <xsl:element name="entity">
         <xsl:attribute name="checked">false</xsl:attribute>
         <xsl:element name="description">table</xsl:element>
         <xsl:element name="name">
    <xsl:value-of select="@name"></xsl:value-of>
    </xsl:element>
         <!--xsl:element name="name">
            <xsl:value-of select="@name"
         </xsl:element-->
         <xsl:element name="contents">
         <xsl:call-template name="list-books">
          <xsl:with-param name="titles" select="namespace/tablename[contains($desired-thread)]"/>          
         </xsl:call-template>
         </xsl:element>
      </xsl:element>
   </xsl:for-each>
</xsl:template><xsl:template name="list-books">
<xsl:param name="titles"/>
<xsl:variable name="first" select="$titles[1]"/>
   <xsl:variable name="rest" select="$titles[position()!=1]"/>
   <xsl:for-each select="attribute">   
   <xsl:element name="entity">
    <xsl:attribute name="checked">false</xsl:attribute>
<xsl:element name="description">attribute</xsl:element>
<xsl:call-template name="expand-resource">
<xsl:with-param name="book" select="$desired-thread"/>
</xsl:call-template>
</xsl:element>
</xsl:for-each>
</xsl:template><xsl:template name="expand-resource">
<xsl:param name="book"/>   
   <xsl:element name="name">
      <xsl:value-of select="attname"/>
   </xsl:element>
   <xsl:element name="type">
    <xsl:value-of select="atttype"/>
   </xsl:element>
   <xsl:element name="num">
    <xsl:value-of select="attnum"/>
   </xsl:element>
<xsl:element name="notnull">
    <xsl:value-of select="notnull"/>
   </xsl:element>
<xsl:element name="namespace">
    <xsl:value-of select="namespace[@id]"/>
   </xsl:element>
</xsl:template></xsl:stylesheet>

解决方案 »

  1.   

    tree.xsl
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" language="JavaScript"><xsl:template match="tree">
      <xsl:apply-templates select="entity"/>
    </xsl:template><xsl:template match="entity">
    <!--<xsl:for-each select="name"> 
    <div status="close" onclick="javascript:return showSubMenu();" color="blue"> 
    <xsl:value-of select="name" /> 
    <xsl:if test="contents"> 
    <xsl:apply-templates match="contents/entity" /> 
    </xsl:if> 
    </div> 
    </xsl:for-each>-->
    <!--<div onclick="javascript:return showSubMenu();clickOnEntity(this);" onselectstart="return false" ondragstart="return false">-->
    <div onclick="window.event.cancelBubble = true;clickOnEntity(this);" onselectstart="return false" ondragstart="return false">
    <xsl:attribute name="STYLE">
    padding-left: 20px;
    <xsl:if expr="depth(this) > 2">
          display: none;
        </xsl:if>
    </xsl:attribute>
        <table border="0" cellspacing="0" cellpadding="0">
        <tr>
        <td valign="middle">
        <img border="0" id="image">
        <xsl:attribute name="SRC">
         <!--<xsl:if test="contents">images/book.gif</xsl:if>-->
           <xsl:choose>
    <xsl:when test="contents">images/NodeImg1.gif</xsl:when>
    <xsl:otherwise>images/NodeImg0.gif</xsl:otherwise>
    </xsl:choose>     
        </xsl:attribute>
        </img>
        </td>
        <td>
         <xsl:choose>
    <xsl:when test="contents"></xsl:when>
    <xsl:otherwise>
    <xsl:element name="input">
    <xsl:attribute name="type">checkbox</xsl:attribute>
    <xsl:attribute name="read">1</xsl:attribute>
    <xsl:attribute name="name">CheckData</xsl:attribute>
    <!--xsl:attribute name="onclick">MouseClick(this)</xsl:attribute-->
    <xsl:attribute name="value">
    <xsl:value-of select="name" />
    </xsl:attribute>
    </xsl:element>
    </xsl:otherwise>
    </xsl:choose>     
    </td>
        <td valign="middle" nowrap="true">
     <xsl:attribute name="STYLE">
              padding-left: 7px;
              font-family: Verdana;
              font-size: 11px;
              font-color: black;
              cursor: hand;
            </xsl:attribute>
             <xsl:value-of select="name"/>
                  </td>
             </tr>
           </table>
              <xsl:apply-templates select="contents/entity"/>
           </div>
    </xsl:template>

    </xsl:stylesheet>
      

  2.   

    我的真正的问题是我想直接从test.xml到tree.html
    不想要中间的other.xml文件
    而且要用jsp或是用javascript程序来实现
      

  3.   

    请问feiyuegaoshan那怎么用java来实现,请说清楚一点好吗?
    或给我写信,.cn
      

  4.   

    javax.xml.transform 里的Transformer提供xsl+xml->xml的变换。
    html也属于xml。
    因此,
    你进行连续两次变换,就得到你的tree.xml了!
      

  5.   

    http://www.vcvj.com/bbs/dispbbs.asp?boardID=3&ID=24
      

  6.   

    byte[] xml = 
                StreamSource xmlSource = new StreamSource(new ByteArrayInputStream(xml));
                //相应XSL
                String xsl = "projectconfig/DeclareAppdix.xsl";
                System.out.println("xsl:"+xsl);
                StreamSource xslSource = new StreamSource(new File(xsl));
                //输出流
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                StreamResult outResult = new StreamResult(out);            //转换为HTML
                TransformerFactory tFactory = TransformerFactory.newInstance();
                Transformer transformer = tFactory.newTransformer(xslSource);
                transformer.transform(xmlSource, outResult);
                result = out.toByteArray();
      

  7.   

    问一下哦,怎么把字符串生成.htm文件呢