XSLT - 如何将节点内的内联/转义 XML 视为嵌套节点 [英] XSLT - How to treat inline/escaped XML within a node as nested nodes
问题描述
xslt 新手 - 到目前为止不喜欢它.
New to xslt - not enjoying it so far.
尝试保留转换为 PDF 的应用程序接收到的某些 HTML(表格)格式.
Trying to preserve some HTML (table) formatting being received by an application that converts to PDF.
需要一种 xslt 方式将 XML 节点中的转义 HTML/XML 数据解释为进一步的子节点吗?
Need an xslt way of interpreting escaped HTML/XML data within an XML node as further child nodes?
已在该节点上尝试过 v3 parse-xml().
已尝试使用 v1 搜索/替换模板将 <
转换为 <
等.尝试过 disable-output-escaping="yes"
- 不.
Have tried a v3 parse-xml() on that node.
Have tried a v1 search/replace template to convert <
into <
etc.
Have tried disable-output-escaping="yes"
- nope.
由于某种原因,似乎没有任何效果.
Nothing appears to work for some reason.
源 XML:
<?xml version="1.0" encoding="windows-1252"?>
<Report>
<node1>node1</node1>
<node2>node2</node2>
<node3>node3</node3>
<node4>
<node4a_with_nested_xml>Nestedxml text$lt;br/$gt;
$lt;b$gt;
$lt;u$gt;blah blah blah$lt;/u$gt;
$lt;/b$gt;
$lt;br/$gt;
$lt;table$gt;
$lt;tr$gt;
$lt;td$gt;
$lt;br/$gt;blah blah blah$lt;br/$gt;
$lt;/td$gt;
$lt;/tr$gt;
$lt;/table$gt;
$lt;b$gt;
$lt;u$gt;blah blah blah$lt;/u$gt;
$lt;/b$gt;
$lt;br/$gt;
$lt;table$gt;
$lt;tr$gt;
$lt;td$gt;
$lt;br/$gt;blah blah blah$lt;/td$gt;
$lt;td$gt;blah blah blah$lt;br/$gt;Other:$lt;/td$gt;
$lt;td$gt;blah blah blah$lt;br/$gt;
$lt;/td$gt;
$lt;/tr$gt;
$lt;/table$gt;
</node4a_with_nested_xml>
</node4>
</Report>
需要解释为:
<?xml version="1.0" encoding="windows-1252"?>
<Report>
<node1>node1</node1>
<node2>node2</node2>
<node3>node3</node3>
<node4>
<node4a_with_nested_xml>
Nestedxml text
<br/>
<b>
<u>blah blah blah</u>
</b>
<br/>
<table>
<tr>
<td>
<br/>blah blah blah<br/>
</td>
</tr>
</table>
<b>
<u>blah blah blah</u>
</b>
<br/>
<table>
<tr>
<td>
<br/>blah blah blah
</td>
<td>
blah blah blah<br/>Other:
</td>
<td>blah blah blah<br/>
</td>
</tr>
</table>
</node4a_with_nested_xml>
</node4>
</Report>
然后从那里我可以开始拉入子节点 &和他们一起做事例如:
Then from there i can start pulling in the child nodes & do stuff with them eg:
<xsl:for-each select="Report">
<xsl:for-each select="node4">
<xsl:for-each select="node4a_with_nested_xml">
<xsl:value-of select="."/>
<xsl:for-each select="table">
<fo:table>
<xsl:for-each select="tr">
<fo:table-row>
<xsl:for-each select="td">
<fo:table-cell>
<xsl:value-of select="."/>
<xsl:for-each select="br">
<fo:block/>
</xsl:for-each>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</xsl:for-each>
</fo:table>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
推荐答案
在 XSLT 1.0 中,您必须分两遍进行转换:首先,在 node4a_with_nested_xml
上禁用输出转义并将结果保存到文件;然后使用另一个 XSLT 样式表处理生成的文件.
In XSLT 1.0 you must do the transformation in two passes: first, disable output escaping on node4a_with_nested_xml
and save the result to a file; then process the resulting file using another XSLT stylesheet.
这是假设您的处理器支持 disable-output-escaping
并且转义的字符串包含格式良好的 XML.
This is assuming that your processor supports disable-output-escaping
and that the escaped string contains well-formed XML.
这篇关于XSLT - 如何将节点内的内联/转义 XML 视为嵌套节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!