带HTML和XSLT转换的XML

问题描述:

我尝试修改一个具有标签内部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

如果你想复制一个元素的混合内容,即包括所有标记,那么你需要使用copy-of而不是value-of。例如:

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

这使输出p元素本身,所有的文字内容和所有的子元素,因此包括等

+0

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