2013-11-20 2 views
0

포맷으로 XML 내용을 통해 반복 :다음 XML 코드를 감안할 때

<section> 
<p>Text...</p> 
<p>More text...</p> 
<special>Text with formatting</special> 
<p>More text..</p> 
</section> 

내가이 출력에 XSLT를 사용하려면 -하지만 <special> 태그가 주변의 HTML 태그 <pre></pre>와 함께해야합니다.

섹션 안에있는 모든 p 요소가 올바른 순서로 나타나게하는 방법을 알아낼 수 없습니다. 도움말 감사.

답변

1

이것은 당신이 그것을 할 수있는 방법이다 : 당신이 필요로하는 새로운 요소 "사전"을 구축 요소 :

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

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:output method="xml" indent="yes"/> 

<xsl:template match="/"> 
    <xsl:apply-templates/> 
</xsl:template> 

<xsl:template match="section"> 
    <xsl:copy> 
    <xsl:apply-templates/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="p"> 
    <xsl:copy> 
    <xsl:value-of select="."/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="special"> 
    <xsl:element name="pre"> 
    <xsl:copy> 
     <xsl:value-of select="."/> 
    </xsl:copy> 
    </xsl:element> 
</xsl:template> 

</xsl:stylesheet> 

결정적인 비트는 XSL입니다.

향후 질문이 있으시면 번 시도한 시간을 가져 와서을 시도하십시오. 단순히 당신이 일하도록 할 수 없다는 말 대신에.

+0

감사합니다. 나는 각자의 구조를 잘 사용하지 못했고, 앞으로의 질문에 대해 당신이 말한 것을 계속 지킬 것입니다. – BTB

1

나는

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

다음은, 예를 들어 특별한 치료를 필요로하는 요소에 대한 템플릿을 추가 신원 변환 템플릿으로 시작할 것

<xsl:template match="special"> 
    <pre> 
    <xsl:call-template name="identity"/> 
    </pre> 
</xsl:template> 
관련 문제