2015-02-05 60 views
0

我正在使用xsl:copy-of来显示完整的节点,但它在顶部和底部添加了其他行。如何删除xslt中的换行符

XML
<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="test.xsl" ?> 
<root> 
    <E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"> 
    <ApplicationData> 
     <TraceData> 
     <DataItem> 
      <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"> 
      <TraceIdentifier>MessageSent.aspx</TraceIdentifier> 
      </TraceRecord> 
     </DataItem> 
     <DataItem> 
      <table> 
      <tr> 
       <td>This should not be a table</td> 
       <td>It must be a text</td> 
      </tr> 
      </table> 
     </DataItem> 
     </TraceData> 
    </ApplicationData> 
    </E2ETraceEvent> 
</root> 

XSLT
<?xml version="1.0" encoding="utf-8"?> 

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:te="http://schemas.microsoft.com/2004/06/E2ETraceEvent" 
       exclude-result-prefixes="te"> 
    <xsl:output method="html" indent="yes"/> 

    <xsl:template match="/"> 
    <output> 
     <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
     <body> 
      <table> 
      <thead> 
       <tr> 
       <td>Data</td> 
       </tr> 
      </thead> 
      <tbody> 
       <xsl:for-each select="//te:E2ETraceEvent"> 
       <tr> 
       <td> 
        <table> 
        <xsl:for-each select=".//te:TraceData//te:DataItem"> 
         <tr> 
         <td> 
          <xmp> 
          <xsl:copy-of select="./node()" /> 
          </xmp> 
         </td> 
         </tr> 
        </xsl:for-each> 
        </table> 
       </td> 
       </tr> 
       </xsl:for-each> 
      </tbody> 
      </table> 
     </body> 
     </html> 
    </output> 
    </xsl:template> 

</xsl:stylesheet> 

输出

引号之间有上述和实际节点

" 
     <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"> 
      <TraceIdentifier>MessageSent.aspx</TraceIdentifier> 
     </TraceRecord> 
    " 
下方的空间和空行

所需的输出

引号之间有一个空格,但没有线路,节点

"  <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"> 
      <TraceIdentifier>MessageSent.aspx</TraceIdentifier> 
     </TraceRecord>" 
+0

,我看到了让像 “ MessageSent.aspx Kash 2015-02-05 17:00:28

+0

Kash 2015-02-05 17:02:26

+0

请发布足够的代码以使我们能够重现问题。您的XSLT没有输出任何引号,因此单独已经没有意义。 – 2015-02-05 17:50:43

回答

0

更改部分的内部./node()*应该解决的问题

你也可以大概问如何删除添加到表标记中的名称空间

基于Remove namespace declaration from XSLT stylesheet with XSLT添加后续荷兰国际集团的部分

<!-- Copy elements --> 
<xsl:template match="*" priority="-1"> 
    <xsl:element name="{name()}"> 
     <xsl:apply-templates select="node()|@*"/> 
    </xsl:element> 
</xsl:template> 

<!-- Copy all other nodes --> 
<xsl:template match="node()|@*" priority="-2"> 
    <xsl:copy />  
</xsl:template> 

,改变

<xsl:copy-of select="*"/> 

<xsl:apply-templates select="*"/> 
+0

非常感谢cilerler为你解答它完美的作品。 – Kash 2015-02-06 13:01:52