给出以下XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<report>
<![CDATA[<?xml version="1.0" encoding="UTF-8"?><whatever><title>GREETING</title><greeting>Hi</greeting><name>Dave</name></whatever>]]>
</report>
</root>
如何使用XSL-T来考虑这个“嵌入式”XML?
我希望在XSL-Transformations之后获得的示例输出是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<TransformedRoot>
<data><html><head><title>GREETING</title></head><body><p>Hi, Dave!</p></body></html>
</TransformedRoot>
假设这是我使用的标准XSL-T:
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="/root">
<TransformedRoot>
<data><!-- How do I get the elements here? --></data>
</TransformedRoot>
</xsl:template>
答案 0 :(得分:1)
Saxon 9的商业版本:
<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="/root">
<TransformedRoot>
<data>
<xsl:apply-templates/>
</data>
</TransformedRoot>
</xsl:template>
<xsl:template match="report">
<xsl:apply-templates select="saxon:parse(normalize-space(.))/node()"/>
</xsl:template>
<xsl:template match="whatever">
<html>
<head>
<xsl:copy-of select="title"/>
</head>
<body>
<p>
<xsl:apply-templates/>
</p>
</body>
</html>
</xsl:template>
<xsl:template match="greeting">
<xsl:value-of select="concat(., ', ')"/>
</xsl:template>
<xsl:template match="name">
<xsl:value-of select="concat(., '!')"/>
</xsl:template>