繁体   English   中英

在java中对html进行Xsl转换

[英]Xsl transformation of html in java

我想使用xsl提取部分html:

<td>    
    <div>    
        <table>    
        <tbody>      
            <tr><td></td><td></td></tr>     
        </tbody>
        <tfoot>   
            <tr>   
                <td></td>    
                <td class="comment-form"><form id="add-comment-586631"></form></td>    
            </tr>    
        </tfoot>   
        </table>   
    </div>   
    <a id="comments-link-586631" class="comments-link" data-comments-count="0" title="ask author for clarification about this post">add comment</a>   
</td>

我想生产这个(div里面的任何东西):

<table>    
            <tbody>      
                <tr><td></td><td></td></tr>     
            </tbody>
            <tfoot>   
                <tr>   
                    <td></td>    
                    <td class="comment-form"><form id="add-comment-586631"></form></td>    
                </tr>    
            </tfoot>   
            </table>

我已尝试使用此示例进行多种排列,但无法正常工作:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://india.com/states">
    <xsl:strip-space elements="*" />
    <xsl:output indent="yes" method="html" />
    <xsl:template match="//div/node()">
            <xsl:copy-of select="*" />
            <xsl:apply-templates />
    </xsl:template>
</xsl:stylesheet>

有人能指出我在这里失踪的东西。 谢谢

如果您只想复制div元素的后代(无需进一步处理),则以下内容应该有效:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:strip-space elements="*" />
   <xsl:output indent="yes" method="html" />

   <xsl:template match="div/node()">
      <xsl:copy-of select="." />
   </xsl:template>

   <xsl:template match="text()"/>
</xsl:stylesheet>

暂无
暂无

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

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