tags:

views:

25

answers:

1

I am using about a dozen XSLT files to provide a large number of output formats. At the moment the user has to know the extension of the file format being exported to e.g. RTF, HTML, TXT.

I would also like to use parameters to allow more options. If I can embed the metadata in the XSL file itself then I can pick up the details by scanning through the files.

Here is what I am thinking about. In this example the program would have to parse the comments for the required information.

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

Are there any standards out there? Do I need to butcher more than one (Dublin Core with a smattering of XML Schema)?

P.S. the project this is being applied to is Argumentative.

+2  A: 

Here is what I am thinking about. In this example the program would have to parse the comments for the required information.

You don't need to code the metadata within comments.

Metadata can be specified as part of the XSLT stylesheet using ordinary XML markup -- as rich in structure and meaning as we need.

Here is an example how to do that:

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

when this transformation is applied on any XML document (not used), the result is:

  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
   "

Do note:

  1. Any element that is in a namespace (of course not the no-namespace and not the xsl namespace) can be specified at the global level of any xslt stylesheet.

  2. Such elements can be accessed using the xslt function document().

Dimitre Novatchev
A wonderful answer. I particularly liked the introspective "document('')/*/meta:metadata"Many thanks
John Hartley
@John_Hartley: Actually, The code was badly formatted -- I have fixed the formatting now.
Dimitre Novatchev