【发布时间】:2012-03-19 06:08:06
【问题描述】:
我尝试修改一个在标签内包含 html 的 xml 文档,我可以转换 <p> 并列出但我里面有粗体和斜体。我怎样才能做到这一点?我使用 xslt 模板进行转换。
这是我的代码:
<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
或者有什么方法可以直接转换代码?
【问题讨论】:
-
正确缩进代码.. 使用常规名称,如
root, foo, bar, child。让您的问题更简单、更整洁.. 尝试将您的工作 XML 文档简化为示例 XML,以便它易于阅读和理解。像这样的问题听起来并不有趣..
标签: html xml xslt apache-fop