2011-04-19 8 views
0

실제로 이름 공간을 추가 할 수 있습니다. 나는 내가보기를 기대하는 결과에 매우 가깝기 때문에. 첫 번째 코드 :자식 노드에 네임 스페이스 접두어 추가 문제

XML :

<helptext> 
    <h6>General configuration options.</h6> 
    <h2>Changing not yet supported.</h2> 
    <p>this is a <b>paragraph</b><br/>this is a new line</p> 
</helptext> 

XSL :

<xsl:template name="transformHelptext"> 
    <xsl:for-each select="./child::*"> 
     <xsl:element name="ht:{local-name()}"> 
      <xsl:choose> 
       <xsl:when test="count(./child::*)>0"> 
        <xsl:call-template name="transformHelptext"/> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:copy-of select="."/> 
       </xsl:otherwise> 
      </xsl:choose> 
     </xsl:element> 
    </xsl:for-each> 
</xsl:template> 

지금까지 너무 좋아. <h6>..</h6><h2>...</h2> 행에는 문제가 없습니다. 그러나 세 번째 줄에는 자식 노드가 <b>입니다. 그리고 어떻게 든 "단락"은이 줄에 대해 표시되는 유일한 텍스트입니다. 나는 choose 진술서에 실수가있다. 그러나 나는 그것을 알아낼 수 없다.

감사

PS : HT 네임 스페이스-XSL 스타일 시트 태그로 정의하고 있습니다 '의 xmlns : HT = "http://www.w3.org/1999/xhtml' '

PS : 내가 뭘하려고하는 것은, 내 특정 XML 노드에 스타일

답변

1

어쩌면 뭔가 대신이 같은 HTML 태그를 적용하는 것이 가능하게됩니다은 "transformHelptext"templeate 내부

<xsl:template name="transformHelptext"> 
    <xsl:apply-templates select="@*|node()" /> 
</xsl:template> 

<xsl:template match="*" > 
    <xsl:element name="ht:{local-name(.)}"> 
     <xsl:apply-templates select="@*|node()" /> 
    </xsl:element> 
</xsl:template> 

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

, 모든 ATTR를 선택 ibutes 및 노드를 만들고 템플릿을 적용합니다.

두 번째 템플릿은 요소 노드를 일치시키고 네임 스페이스를 변경합니다. 세 번째 템플릿은 특성 노드와 텍스트 노드를 일치시키고 복사본을 만듭니다.

+0

답장을 보내 주셔서 감사합니다. 그러나 브라우저가 파이어 폭스가 아니면 일반 텍스트 만 표시합니다. – savruk

+0

@savruk 어쩌면 xml 헤더가 누락되었습니다 – Stephan

+0

실제로 당신의 코드로 작업 해 주셔서 감사합니다 – savruk

1

입력 XML :

<?xml version="1.0" encoding="UTF-8"?> 
<helptext> 
    <h6>General configuration options.</h6> 
    <h2>Changing not yet supported.</h2> 
    <p>this is a <b>paragraph</b><br/>this is a new line</p> 
</helptext> 

XSLT :

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="*|@*"> 
    <xsl:element name="ht:{local-name()}" namespace="http://www.w3.org/1999/xhtml"> 
     <xsl:copy-of select="@*"/> 
     <xsl:apply-templates/> 
    </xsl:element> 
</xsl:template> 

출력 XML :

,491,629,281,

토론 : 가능하면 <xsl:for-each>을 사용하면 프로세서 속도가 느려질 수 있으므로 사용하지 마십시오.

+0

+1 팁. – savruk