问题
New to xslt - not enjoying it so far.
Trying to preserve some HTML (table) formatting being received by an application that converts to PDF.
Need an xslt way of interpreting escaped HTML/XML data within an XML node as further child nodes?
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.
Source 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>
Needs to be interpreted as:
<?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>
回答1:
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.
This is assuming that your processor supports disable-output-escaping
and that the escaped string contains well-formed XML.
来源:https://stackoverflow.com/questions/57798465/xslt-how-to-treat-inline-escaped-xml-within-a-node-as-nested-nodes