问题描述
所以,我有很多 XSLT 文件需要生成预览,但是我没有相应的 XML 文件.我想知道是否可以通过 XSLT 文件并为该 XSLT 创建必填字段列表?例如,
So, I have quite a few XSLT files that I need to generate a preview for, however I do not have the corresponding XML files. I was wondering if it was possible to go through an XSLT file and create a list of the required fields for that XSLT? For example,
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我想从那个 XSLT 转到这个:"/catalog/cd/title,/catalog/cd/artist" 因为它们是这个 XSLT 所需的字段,或者为所有这些字段设置一个默认值以便它输出标题为/catalog/cd/title",艺术家为/catalog/cd/artist".
I want to go from that XSLT to this: "/catalog/cd/title, /catalog/cd/artist" as they are the fields required by this XSLT, or set a default value for all of them so it outputs "/catalog/cd/title" for title and "/catalog/cd/artist" for artist.
推荐答案
只是试一试,这也不适用于多个模板:
just to give it a shot, also this won't work with multiple templates:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" exclude-result-prefixes="xsl">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="xsl-namespace">http://www.w3.org/1999/XSL/Transform</xsl:variable>
<xsl:template match="*[namespace-uri() != $xsl-namespace]" >
<xsl:copy>
<xsl:apply-templates select="@*[namespace-uri() != $xsl-namespace]"/>
<xsl:apply-templates select="*[namespace-uri() != $xsl-namespace]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*[namespace-uri() != $xsl-namespace]" >
<xsl:copy/>
</xsl:template>
这篇关于从 xslt 向后工作以创建 xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!