2012-02-29 75 views
1

我嘗試修改一個具有標籤內部html的xml文檔,我可以轉換<p>和列表,但內部有粗體和斜體。我怎樣才能做到這一點?我使用xslt模板進行轉換。帶HTML和XSLT轉換的XML

這是我的代碼:

<Memoria>  
    <titulo>Memoria EUITI 2010</titulo> 
    <Indice> 
    <titulo>Indice 2010</titulo> 
    <secciones> 
     <seccion> 
     <parent_id>1</parent_id> 
     <titulo>INFORMACI&#211;N GENERAL</titulo> 
      <contenido><p><strong>ESTO</strong> ES UNA <em>PRUEBA</em></p></contenido> 
<ul> 
    <li> caso de poner</li> 
</ul> 
<p>Ver si funciiona esto que si funciona ya esta</p> 
<p> </p></contenido 
     </seccion> 
    </secciones> 
    </Indice> 
</Memoria> 

我使用XSLT轉換:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" 
> 
    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="/"> 

    <Memoria> 
     <xsl:apply-templates select="//Memoria"/> 
    </Memoria> 
    </xsl:template> 
    <xsl:template match="text()"/> 

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

    <xsl:template match="Indice/titulo"> 
    <Indice> 
     <xsl:value-of select="."/> 
    </Indice> 
    </xsl:template> 

    <xsl:template match="Indice/secciones/seccion"> 
    <Seccion> 
     <xsl:apply-templates select="contenido|titulo"/> 
    </Seccion> 

    </xsl:template> 

    <xsl:template match="Indice/secciones/seccion/titulo"> 
    <nombre_seccion> 
     <xsl:value-of select="."/> 
    </nombre_seccion> 
    </xsl:template> 


    <xsl:template match="contenido"> 
    <Contenido> 
     <xsl:apply-templates select="p|ul"/> 
    </Contenido> 
    </xsl:template> 


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

    <xsl:template match="ul"> 
    <ul> 
     <xsl:for-each select="li"> 
    <li> 
     <xsl:value-of select="."/> 
    </li> 
     </xsl:for-each> 
    </ul> 
</xsl:template> 
</xsl:stylesheet> 

有了這個模板,我得到一個XML有效證件,但該文件沒有進去:

<contenido><p><strong>ESTO</strong> ES UNA <em>PRUEBA</em></p></contenido> 

我該如何做到這一點?

另一方面,我想將此結果文檔與XSL-FO中的另一個XSLT進行轉換,以生成帶有FOP的PDF。我可以生成p和一個列表,但我不能生成粗體和草書。

這是正確的方式做到這一點:

HTML的「基於XML> XSL-FO

還是有直接轉換代碼的方法呢?

+0

縮進的代碼正確..使用傳統的名字,像'根,富,酒吧,孩子'。保持你的問題簡單而整齊。儘量減少你的XML文檔的工作量,以使它可讀,易於理解。像這樣的問題幾乎聽起來很有趣.. – 2012-03-01 13:48:25

回答

1

如果你想複製一個元素的混合內容,即包括所有標記,那麼你需要使用copy-of而不是value-of。例如:

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

這使輸出p元素本身,所有的文字內容和所有的子元素,因此包括等

+0

非常感謝 – user1075738 2012-03-02 18:33:07