XSLT管理 - 将元数据附加到样式表以获取输出和参数

Joh*_*ley 6 xslt

我正在使用大约十几个XSLT文件来提供大量的输出格式.目前,用户必须知道要导出的文件格式的扩展名,例如RTF,HTML,TXT.

我还想使用参数来允许更多选项.如果我可以将元数据嵌入到XSL文件中,那么我可以通过扫描文件来获取详细信息.

这是我在想的.在此示例中,程序必须解析所需信息的注释.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Title: Export to Rich Text Format -->
<!-- Description: This Stylesheet converts to a Rich Text Format format which may be used in a word processor such as Word -->
<!-- FileFormat: RTF -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="CompanyName"/> <!-- Format:String, Description: Company name to be inserted in the footer -->
<xsl:param name="DateDue"/> <!-- Format:Date-yyyy-mm-dd, Description: Date Due -->
<xsl:param name="IncludePicture">true</xsl:param><!-- Format:Boolean, Description: Do you want to include a graphical representation? -->
  <xsl:template match="/">
  <!-- Stuff -->
  </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

那里有标准吗?我是否需要屠宰多个(都柏林核心与一些XML Schema)?

PS正在应用的项目是议论文.

Dim*_*hev 6

这是我在想的.在此示例中,程序必须解析所需信息的注释.

并不需要在注释中编码的元数据.

可以使用普通的XML标记将元数据指定为XSLT样式表的一部分 - 因为我们需要丰富的结构和含义.

以下是如何执行此操作的示例:

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

 <meta:metadata>
   <title>Title: Export to Rich Text Format </title>
   <description>
    This Stylesheet converts to a Rich Text
    Format format which may be used in a word processor
    such as Word
   </description>
   <fileFormat>RTF</fileFormat>
   <parameters>
     <parameter name="CompanyName" format="xs:string"
      Description="Company name to be inserted in the footer"/>

     <parameter name="DateDue" format="xs:date"
      Description="Date Due"/>

     <parameter name="IncludePicture" format="xs:boolean"
      Description="Do you want to include a graphical representation?"/>
   </parameters>
 </meta:metadata>

 <xsl:param name="CompanyName"/>
 <xsl:param name="DateDue"/>
 <xsl:param name="IncludePicture" select="true"/>

 <xsl:variable name="vMetadata" select=
      "document('')/*/meta:metadata"/>

 <xsl:template match="/">
  This is a demo how we can access and use the metadats.

  Metadata --> Description:

  "<xsl:copy-of select="$vMetadata/description"/>"
 </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

当此转换应用于任何XML文档(未使用)时,结果为:

  This is a demo how we can access and use the metadats.

  Metadata --> Description:

  "
    This Stylesheet converts to a Rich Text
    Format format which may be used in a word processor
    such as Word
   "
Run Code Online (Sandbox Code Playgroud)

请注意:

  1. 可以在任何xslt样式表的全局级别指定命名空间中的任何元素(当然不是无命名空间而不是xsl命名空间).

  2. 可以使用xslt函数访问这些元素document().