Html 用xsl 3.0选择/转换表元素
在使用XSL样式表转换页面的XML文档中选择HTML表时遇到问题 我正在尝试使用class=“table factbook”选择表格。XML看起来像:Html 用xsl 3.0选择/转换表元素,html,xml,xslt,Html,Xml,Xslt,在使用XSL样式表转换页面的XML文档中选择HTML表时遇到问题 我正在尝试使用class=“table factbook”选择表格。XML看起来像: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]> <document> <headcode></headcode> &l
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<document>
<headcode></headcode> <!-- before closing head tag -->
<bodycode></bodycode> <!-- after opening body tag -->
<footcode></footcode> <!-- before closing body tag -->
<h4>University of Georgia Fact Books</h4>
<table class="table factbook">
<caption>Table becomes a bunch of divs</caption>
<tbody>
<tr>
<td>
<h3>2016</h3>
<a href="/_resources/files/factbook/FactBook2016.pdf"><img class="img-responsive" style="max-width: 167px; border: solid 1px #272727;" src="/_resources/files/factbook/2016FB_Cover_thumb.jpg" alt="" /></a></td>
<td>
<h3>2015</h3>
<a href="/_resources/files/factbook/FactBook2015.pdf"><img class="img-responsive" style="max-width: 167px; border: solid 1px #272727;" src="/_resources/files/factbook/2015FB-Cover_thumb.png" alt="" /></a></td>
<td>
<h3>2014</h3>
<a href="/_resources/files/factbook/FactBook2014.pdf"><img class="img-responsive" style="max-width: 167px; border: solid 1px #272727;" src="/_resources/files/factbook/2014FB-Cover_thumb.png" alt="" /></a></td>
<td>
<h3>2013</h3>
<a href="/_resources/files/factbook/FactBook2013.pdf"><img class="img-responsive" style="max-width: 167px; border: solid 1px #272727;" src="http://69.39.227.24/_resources/files/factbook/2013FB-Cover_thumb.png" alt="" /></a></td>
</tr>
</tbody>
</table>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="html" indent="yes" encoding="UTF-8" include-content-type="no" />
<xsl:strip-space elements="*"/>
<!-- factbook transformation -->
<xsl:template match="//table[@class='table factbook']">
<xsl:for-each select="tbody/tr/td">
<div class="grid">
<xsl:copy-of select="node()"/>
</div>
</xsl:for-each>
</xsl:template>
<xsl:template match="/document">
<xsl:text disable-output-escaping="yes"><!DOCTYPE HTML></xsl:text>
<html lang="en">
<head>
<xsl:apply-templates select="headcode/node()"/>
</head>
<body>
<xsl:apply-templates select="bodycode/node()"/>
<div class="wrap" role="document">
<div class="content">
<div class="container">
<xsl:call-template name="page-content"/>
</div>
</div>
</div>
<xsl:apply-templates select="footcode/node()"/> <!-- pcf -->
</body>
</html>
</xsl:template>
<xsl:template name="page-content">
<xsl:copy-of select="/document">
</xsl:template>
</xsl:stylesheet>
乔治亚大学实况图书
桌子变成了一堆div
2016
2015
2014
2013
XSL看起来像:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<document>
<headcode></headcode> <!-- before closing head tag -->
<bodycode></bodycode> <!-- after opening body tag -->
<footcode></footcode> <!-- before closing body tag -->
<h4>University of Georgia Fact Books</h4>
<table class="table factbook">
<caption>Table becomes a bunch of divs</caption>
<tbody>
<tr>
<td>
<h3>2016</h3>
<a href="/_resources/files/factbook/FactBook2016.pdf"><img class="img-responsive" style="max-width: 167px; border: solid 1px #272727;" src="/_resources/files/factbook/2016FB_Cover_thumb.jpg" alt="" /></a></td>
<td>
<h3>2015</h3>
<a href="/_resources/files/factbook/FactBook2015.pdf"><img class="img-responsive" style="max-width: 167px; border: solid 1px #272727;" src="/_resources/files/factbook/2015FB-Cover_thumb.png" alt="" /></a></td>
<td>
<h3>2014</h3>
<a href="/_resources/files/factbook/FactBook2014.pdf"><img class="img-responsive" style="max-width: 167px; border: solid 1px #272727;" src="/_resources/files/factbook/2014FB-Cover_thumb.png" alt="" /></a></td>
<td>
<h3>2013</h3>
<a href="/_resources/files/factbook/FactBook2013.pdf"><img class="img-responsive" style="max-width: 167px; border: solid 1px #272727;" src="http://69.39.227.24/_resources/files/factbook/2013FB-Cover_thumb.png" alt="" /></a></td>
</tr>
</tbody>
</table>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="html" indent="yes" encoding="UTF-8" include-content-type="no" />
<xsl:strip-space elements="*"/>
<!-- factbook transformation -->
<xsl:template match="//table[@class='table factbook']">
<xsl:for-each select="tbody/tr/td">
<div class="grid">
<xsl:copy-of select="node()"/>
</div>
</xsl:for-each>
</xsl:template>
<xsl:template match="/document">
<xsl:text disable-output-escaping="yes"><!DOCTYPE HTML></xsl:text>
<html lang="en">
<head>
<xsl:apply-templates select="headcode/node()"/>
</head>
<body>
<xsl:apply-templates select="bodycode/node()"/>
<div class="wrap" role="document">
<div class="content">
<div class="container">
<xsl:call-template name="page-content"/>
</div>
</div>
</div>
<xsl:apply-templates select="footcode/node()"/> <!-- pcf -->
</body>
</html>
</xsl:template>
<xsl:template name="page-content">
<xsl:copy-of select="/document">
</xsl:template>
</xsl:stylesheet>
!DOCTYPE HTML>
请发布您想要的结果以及当前得到的结果或错误。我不明白XSLT只使用<代码> <代码>和不声明XSLT命名空间的方式可以被解析或完全执行。我在末尾添加了命名空间和预期结果。考虑发布最小但完整的样本以允许我们重现这个问题。输入没有根元素的结束标记,并且未声明使用的实体引用。因此,请详细解释如何解析输入并将其提供给哪个XSLT处理器。模板不匹配的常见问题是名称空间,因此可能match=“/document/table[@class='table factbook']”不匹配,因为用于解析输入的HTML解析器将其元素放入名称空间,如果是HTML解析器,则可能是XHTML名称空间。因此,在这种情况下,您需要确保使用xpath默认名称空间=”http://www.w3.org/1999/xhtml“
在样式表的根元素上,或者至少在要匹配HTML元素的模板上。感谢您的帮助。我确实发布了完整的XSL和XML,以便您可以看到。我最终发现我用了