1

我有一个 XSLT 正在处理的 XML 文件,以生成另一个 XML 文件。

是否有一种简单的方法可以了解 XSLT 将引用以生成输出文件的原始 XML 消息中的所有可能元素/属性?

如果我查看 w3school.com 网站 ( http://www.w3schools.com/xsl/xsl_transformation.asp ) 上的示例,那么目录 XML 包含价格和年份等项目,但 XSLT 只会拉目录/cd/标题和目录/CD/艺术家。

所以我需要某种自动化的魔法工具,它可以分析 xslt(可能是输入文件模式),为我提供输出文件将包含的某种属性列表。

感谢您的帮助

4

3 回答 3

0

不过想象力很好!出色地。目前没有这样的工具可以分析 XSLT 并让您知道“它在 XML 文件中引用的所有元素/属性”!你必须手动做..

于 2012-12-06T11:04:36.020 回答
0

It isn't difficult to produce such tool yourself:

Add to any template that matches element(s) or attribute(s):

<xsl:message>
 <!-- Put all the data here that identifies the element attribute,
      for example the Xpath expression that selects the current node
 -->
</xsl:message>

You can use existing transformations that take a node and produce one XPath expression that selects the node -- invoke them inside the above xsl:message. See for example this: Generate/get xpath from XML node java

Then what you need to do is to combine all these generated XPath expressions with the | operator and to evaluate the resulting XPath expression -- this will select all elements and attributes that are actually referenced in the transformation.

If you also want to account for the elements/attributes that are processed by the XSLT built-in templates, simply override those with specific templates in your transformation -- this is a good practice that as additional benefit may find errors in your transformation.

于 2012-12-06T13:50:45.730 回答
0

如果您将 xslt 文件更改为此

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

如果有帮助,它会向您显示原始文件的副本?

于 2012-12-06T10:27:50.487 回答