2016-04-28 9 views
2

私のようなXML入力持っている:私はXSLTの新たなんだし、それを行うにはどのよう見当がつかない混合コンテンツを扱うには?

<File> 
    <para>Start of text</para> 
    <para>link text</para> 
    <para>Back to section.</para> 
</File> 

:として

<root> 
    <section>Start of text<link>link text</link>Back to section.</section> 
</root> 

をそして、私は、出力XMLを取得するには、XSLTを使用することを願っています。なにか提案を?ありがとう!

アップデート:これが私の現在のXSLTが

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

<xsl:template match="root"> 
    <File> 
     <xsl:apply-templates/> 
     <xsl:if test="descendant::inner"> 
      <para> 
       <xsl:value-of select="descendant::inner"/> 
      </para> 
     </xsl:if> 
    </File> 
</xsl:template> 

<xsl:template match="section"> 
    <xsl:element name="para"> 
     <xsl:value-of select="text()"/> 
    </xsl:element> 
</xsl:template> 

のように見え、ここでは出力ですです:

<File> 
    <para>Start of textStart of text</para> 
    <para>link text</para> 
</File> 

ありがとう!

答えて

1

ただ、このようなpara要素とrootの任意の非空降順text()ノード囲む:出力される

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

    <xsl:template match="/root"> 
    <File> 
     <xsl:for-each select=".//text()"> 
     <xsl:if test="normalize-space(.) != ''"> 
      <para>  
      <xsl:value-of select="normalize-space(.)"/> 
      </para> 
     </xsl:if> 
     </xsl:for-each> 
    </File> 
    </xsl:template> 

</xsl:stylesheet> 

を:

<?xml version="1.0"?> 
<File> 
    <para>Start of text</para> 
    <para>link text</para> 
    <para>Back to section.</para> 
</File> 
関連する問題