2017-08-02 25 views
-1

鑑於我有下面的XMLXSLT/XML:從嵌套元素展開價值

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-model href="http://www.stoa.org/epidoc/schema/8.19/tei-epidoc.rng" 
schematypens="http://relaxng.org/ns/structure/1.0"?> 
<?xml-model href="http://www.stoa.org/epidoc/schema/8.19/tei-epidoc.rng" 
schematypens="http://purl.oclc.org/dsdl/schematron"?> 
<?xml-stylesheet type="text/xsl" href="tei_poetry_parse2.xslt"?> 

<TEI> 
    <l>In nova fert animus mutatas dicere formas</l> 
    <l>corpora; di, coeptis (nam vos mutastis et illas)</l> 
</TEI> 

,我想轉換到下面的代碼XSLT

<lb /> 
In nova fert animus mutatas dicere formas 
<lb /> 
corpora; di, coeptis (nam vos mutastis et illas) 

所以基本上我想提取文本內容並將其放在元素後面(我想要更改爲空或自動關閉<lb>。 我試過以下XSLT樣式表:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="http://www.tei-c.org/ns/1.0" version="2.0"> 
    <xsl:output method="xml"/> 


    <xsl:template match="/"> 
     <text> 

      <title>Text</title> 

      <xsl:apply-templates/> 

     </text> 

    </xsl:template> 

    <xsl:template match="l" xmlns="http://www.tei-c.org/ns/1.0"> 

     <lb /> 
     <xsl:value-of select="(text())"/> 

    </xsl:template> 



</xsl:stylesheet> 

當我轉換的時候,所有的<lb>標籤都嵌套在一起。當我將輸出方法更改爲html時,它可以工作,但我需要XML作爲輸出。 我會很高興的任何幫助!

我能得到什麼: DOM

+0

這是你的整個樣式表? –

+1

「*當我轉換它時,所有標籤都嵌套在一起。*」不,它們不是。請提供一個**完整的例子,使我們能夠重現問題 - 請參閱:[mcve]。 –

+0

對不起。我將提供完整的樣式表和XML: – Bene

回答

0

讓我們有一個簡單的工作示例:

XML

<TEI xmlns="http://www.tei-c.org/ns/1.0" > 
    <l>In nova fert animus mutatas dicere formas</l> 
    <l>corpora; di, coeptis (nam vos mutastis et illas)</l> 
</TEI> 

XSLT 2.0

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xpath-default-namespace="http://www.tei-c.org/ns/1.0" > 
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/> 

<xsl:template match="/TEI"> 
    <text> 
     <title>Text</title> 
     <xsl:apply-templates/> 
    </text> 
</xsl:template> 

<xsl:template match="l"> 
    <lb/> 
    <xsl:value-of select="."/> 
</xsl:template> 

</xsl:stylesheet> 

結果

<text> 
    <title>Text</title> 
    <lb/>In nova fert animus mutatas dicere formas 
    <lb/>corpora; di, coeptis (nam vos mutastis et illas) 
</text> 

演示:http://xsltransform.net/a9Gixb

+0

這似乎是我的應用程序的問題。無論如何謝謝你的回答! – Bene

+0

它確實需要XSLT 2.0處理器。如果您的應用程序使用XSLT 1.0,則需要使用前綴而不是'xpath-default-namespace'。 –