我想用一个通用的xslt来显示我的xslt,以便生成一个关于如何构建xslt的文档。我在stackoverflow上得到了一些帮助,但仍然有一些细节我认为我可以自己完成,但不幸的是没有。
上一篇文章:Generate xsl documentation
我希望它是这样工作的:
我的xslt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<head>
<title>My sample</title>
</head>
<body>
My sample element: <xsl:value-of select="root/element1"/>
</body>
</xsl:template>
</xsl:stylesheet>请求的输出:
<html>
<head>
<title>My sample</title>
</head>
<body>
My sample element: root/element1
</body>
</html>如果可能,我还想显示for-each循环和If语句。有没有人这样做过,可以和我分享一些代码?
发布于 2018-04-17 18:15:43
我做了一些修改,我想它可以帮助你,请检查代码并在你的输入上运行它::
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output method="text"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:value-of select="concat('<', name())" />
<xsl:apply-templates select="@*" />
<xsl:value-of select="'>'" />
<xsl:apply-templates/>
<xsl:value-of select="concat('</', name(), '>')" />
</xsl:template>
<xsl:template match="@*">
<xsl:value-of select="concat(' ', name(), '="', ., '"')" />
</xsl:template>
<xsl:template match="xsl:*">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="xsl:value-of">
<xsl:value-of select="@select" />
</xsl:template>
<!-- add appropriate templates for the other XSLT elements -->
</xsl:stylesheet>https://stackoverflow.com/questions/10412776
复制相似问题