XSLT Management - Binding Metadata to a Style Sheet for Output and Parameters

I use about a dozen XSLT files to provide a large number of output formats. At the moment, the user must know the extension of the file format exported, for example. RTF, HTML, TXT.

I would also like to use parameters to allow more parameters. If I can embed metadata in the XSL file itself, I can get the details by looking at the files.

That’s what I’m thinking about. In this example, the program will have to analyze the comments for the necessary 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? Do I need to hammer in more than one (Dublin core with a small amount of XML schema)?

PS the project to which it is applied is equal to Argumentative .

+6
xslt
source share
1 answer

This is what I think. In this example, the program will need to parse the comments for the required information.

You do not need to encode metadata in the comments.

Metadata can be specified as part of an XSLT stylesheet using regular XML markup - as rich in structure and value as we need .

Here is an example of how to do this:

 <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 conversion is applied to any XML document (not used), the result :

  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 " 

Please note :

  • Any element that is in the namespace (of course, not in the namespace, but not in the xsl namespace) can be set at the global level of any xslt stylesheet.

  • These elements can be accessed using the xslt document() function.

+6
source share

All Articles