Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT management - attaching metadata to a stylesheet for output and parameters

Tags:

xslt

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.

like image 600
John Hartley Avatar asked Aug 13 '10 02:08

John Hartley


People also ask

Which XSLT element is used to write literal text to the output?

The <xsl:text> element writes literal text to the output tree.

What is the purpose of XSLT style sheets write an XSLT style sheet?

XSLT Processor takes the XSLT stylesheet and applies the transformation rules on the target XML document and then it generates a formatted document in the form of XML, HTML, or text format. This formatted document is then utilized by XSLT formatter to generate the actual output which is to be displayed to the end-user.

Can you use CSS with XSLT?

An XSLT style sheet can emit HTML <STYLE> elements, including CSS specifications, directly into the HTML that results from the XSLT transformation. This option works best when the number of CSS rules is small and easily managed.


1 Answers

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().

like image 139
Dimitre Novatchev Avatar answered Sep 19 '22 13:09

Dimitre Novatchev