生成 xsl 文档 [英] Generate xsl documentation

查看:36
本文介绍了生成 xsl 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 php 为我的 xsl 生成一个可视化的文档".我想要做的基本上是在没有 XML 的情况下转换我的 xsl,以便显示 XML 字段在 HTML 中的显示方式.

Id like to generate a visual "documentation" for my xsl using php. What I want to do is basically to transform my xsl without an XML inorder to display how the XML fields will be displayed in the HTML.

澄清:

xsl:

<?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>

有人知道怎么做吗?

BR,杰克

推荐答案

XSLT 是输入驱动的.如果会为不同的输入生成不同的输出.

XSLT is input-driven. If will generate different output for different input.

在任何比您的简单示例更复杂的实际场景中,在没有任何输入的情况下查看代码意味着您无法说出输出会是什么样子.

In any real-world scenario that is more complex than your simple example, looking at the code without any input to run through it means you can't say what the output is going to look like.

对于您的简单示例,您可以通过另一个 XSLT 样式表运行您的 XSLT 样式表.

For your simple example, you could run your XSLT stylesheet thorugh another XSLT stylesheet.

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
  <xsl:output method="text" />

  <xsl:template match="*">
    <xsl:value-of select="concat('&lt;', name())" />
    <xsl:apply-templates select="@*" />
    <xsl:value-of select="'&gt;'" />
    <xsl:apply-templates select="*" />
    <xsl:value-of select="concat('&lt;/', name(), '&gt;')" />
  </xsl:template>

  <xsl:template match="@*">
    <xsl:value-of select="concat(' ', name(), '=&quot;', ., '&quot;')" />
  </xsl:template>

  <xsl:template match="xsl:*">
    <xsl:apply-templates select="*" />
  </xsl:template>

  <xsl:template match="xsl:value-of">
    <xsl:value-of select="concat('{{value-of: ', @select, '}}')" />
  </xsl:template>

  <!-- add appropriate templates for the other XSLT elements -->
</xsl:stylesheet>

使用您的示例,这会生成字符串

With your sample, this produces the string

<head><title></title></head><body>{{value-of: root/element1}}</body>

然而,为其他 XSLT 元素添加适当的模板" 部分是困难的部分.您的输出将按照输入的顺序排列(正如我所说,XSLT 是输入驱动的).您的 XSLT 程序很可能不会以与其将要生成的输出相同的方式进行布局,因此从中生成合理的文档可能比您想象的要困难得多.

However, the "add appropriate templates for the other XSLT elements" part is the difficult bit. Your output will be in the order of the input (XSLT is input-driven, as I said). Your XSLT program will most likely not be layed out the same way as the output it is going to produce, so generating sensible documentation from it might be quite a bit harder than you think.

这篇关于生成 xsl 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆