我嘗試修改一個具有標籤內部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Ó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
還是有直接轉換代碼的方法呢?
縮進的代碼正確..使用傳統的名字,像'根,富,酒吧,孩子'。保持你的問題簡單而整齊。儘量減少你的XML文檔的工作量,以使它可讀,易於理解。像這樣的問題幾乎聽起來很有趣.. – 2012-03-01 13:48:25