2013-06-22 4 views
0

나는 XML 문서에서 성공하지 텍스트 노드를 제거하기 위해 노력하고있어 제거, 이것은 내가 사용하고있어 XSLT입니다 : 다른 라인이기 때문에XSLT 모든 텍스트 노드

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0"> 
    <xsl:output method="xml"/> 

    <xsl:template match="/*"> 
     <xsl:copy> 
      <xsl:apply-templates select="node()" /> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="/*/*"> 
     <xsl:element name="x"> 
      <xsl:attribute name="attr"> 
       <xsl:value-of select="name()"/> 
      </xsl:attribute> 
      <xsl:apply-templates select="node()" /> 
     </xsl:element> 
    </xsl:template> 

    <xsl:template match="/*/*/a"> 
     <xsl:copy> 
      <xsl:apply-templates select="node()" /> 
     </xsl:copy> 
    </xsl:template> 

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

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

    <xsl:template match="/*/*/*[not(self::a)]" /> 
    <xsl:template match="text()" /> 

</xsl:stylesheet> 

라인 <xsl:template match="text()"> 아마 작동하지 않습니다 더 구체적인 (생각합니다), 어떻게 모든 텍스트 노드를 제거 할 수 있습니까?

답변

3

텍스트 노드를 억제하기위한 템플릿은 일치하는 템플릿을 찾는 모든 텍스트 노드를 억제합니다. 그러나 모든 텍스트 노드가 적용 템플릿을 사용하여 처리되는 것은 아니기 때문에 모든 텍스트 노드를 억제하지는 않습니다. 일부 일치하는 패턴 (일치 패턴 /*/*/a/*/*/*/*과 일치하는 노드가있는 경우 템플릿을 적용하지 않고 모든 자식 노드를 복사하고 해당 자식 중 일부가 텍스트 노드이거나 해당 자식 중 일부가 텍스트 노드 자손을 가지고있는 경우 그 텍스트 노드가 여러분의 낫을 벗어납니다. 사본을 없애고 apply-templates로 복사하십시오.

+0

고맙습니다. – MoreOver