2012-06-13 3 views
1

다른 사람의 문제를 해결하려고 시도했지만 그 대신 내 자신의 이상한 문제가 발생했다는 것이 확실합니다. 그러나 아직 답은 간단합니다.XSLT 요소 정렬에서 출력

는 XML 내가 가진 :

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

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

    <xsl:template match="info"> 
    <xsl:copy> 
     <xsl:element name="content"> 
     <xsl:for-each select="content"> 
      <xsl:apply-templates select="@*"/> 
      <xsl:apply-templates select="node()"/> 
     </xsl:for-each> 
     </xsl:element> 
    </xsl:copy> 
    </xsl:template> 

</xsl:stylesheet> 

이 (가) 작성 :

XSLT와
<xml> 
    <head> 
    <info> 
     <content> 
     <source attribute1="RSC1985s5c1" attribute2="6(17)"> 
      data1 
     </source> 
     <cite/> 
     <case/> 
     (
     <target attribute1="LRC1985s5c1" attribute2="6(17)1"> 
      3e/191 
     </target> 
     ) 
     </content> 
     <content> 
     <source attribute1="RSC1985s5c1" attribute2="6(17)"> 
      data2 
     </source> 
     <cite/> 
     <case/> 
     (
     <target attribute1="LRC1985s5c4" attribute2="6(17)1"> 
      4e/54 
     </target> 
     ) 
     </content> 
    </info> 
    </head> 
</xml> 

는이 개 내용 요소를 결합하는

<?xml version="1.0" encoding="utf-8"?><xml> //Just noticed here too! 
    <head> 
    <info><content> //Why no new line here? 
     <source attribute1="RSC1985s5c1" attribute2="6(17)"> 
      data1 
     </source> 
     <cite /> 
     <case /> 
     (
     <target attribute1="LRC1985s5c1" attribute2="6(17)1"> 
      3e/191 
     </target> 
     ) 

     <source attribute1="RSC1985s5c1" attribute2="6(17)"> 
      data2 
     </source> 
     <cite /> 
     <case /> 
     (
     <target attribute1="LRC1985s5c4" attribute2="6(17)1"> 
      4e/54 
     </target> 
     ) 
     </content></info> //And again here? 
    </head> 
</xml> 

주석을 사용하여 강조 표시된 문제는 무엇입니까 I 알아낼 수없는 이유는 요소 사이에 새로운 라인이 없다는 것입니다.

미리 감사드립니다. 제공된 변형으로

답변

1

약간 수정 :

I는 색슨 6.5.5 다른 XSLT 1.0 다수의 프로세서로 잘 들여 출력을 얻을
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 
<xsl:strip-space elements="*"/> 

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

    <xsl:template match="info"> 
    <xsl:copy> 
     <xsl:element name="content"> 
     <xsl:for-each select="content"> 
      <xsl:apply-templates select="@*"/> 
      <xsl:apply-templates select="node()"/> 
     </xsl:for-each> 
     </xsl:element> 
    </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

:

<xml> 
    <head> 
     <info> 
     <content> 
      <source attribute1="RSC1985s5c1" attribute2="6(17)"> 
      data1 
     </source> 
      <cite/> 
      <case/> 
     (
     <target attribute1="LRC1985s5c1" attribute2="6(17)1"> 
      3e/191 
     </target> 
     ) 
     <source attribute1="RSC1985s5c1" attribute2="6(17)"> 
      data2 
     </source> 
      <cite/> 
      <case/> 
     (
     <target attribute1="LRC1985s5c4" attribute2="6(17)1"> 
      4e/54 
     </target> 
     ) 
     </content> 
     </info> 
    </head> 
</xml> 

일부 XSLT 프로세서는 여전히 원치 않는 들여 쓰기를 생성 할 수 있습니다. - W3C XSLT 1.0 권장 사항에는 엄격한 표준이 없습니다. xently 들여 쓰기가 수행되어야합니다.

+0

원하는대로 작동하지만 내 프로세서는 빈 요소의 들여 쓰기를 약간 다르게 처리하지만 Microsoft는 그 작업을 약간 다릅니다. 평소와 같이 신속하고 완벽한 답변을드립니다! – Mike

+0

@ 마이크 : 천만에. –