BaH.Libxslt: Constants Functions Types Modinfo Source  

Libxslt

Libxslt is the XSLT processor developed for the Gnome project.
This is the BlitzMax implementation of the libxslt library.

XSLT itself is a an XML language to define transformation for XML. Libxslt is based on libxml2 the XML library developed for the Gnome project.
For more information on XSLT, visit the XSLT website.

You need the BaH.Libxml module in order to build applications which use Libxslt.

Here are some key points about libxslt:

Basic Use

Doing an XSLT transformation can be done in a few simple steps:

  1. configure the parser for XSLT:

    xmlSubstituteEntitiesDefault();
    xmlLoadExtDtdDefaultValue = 1

  2. parse the stylesheet with TxsltStylesheet.parseStylesheetFile()
  3. parse the document with TxmlDoc.parseFile()
  4. apply the stylesheet using applyStylesheet()
  5. save the result using saveResultToFilename() if needed set xmlIndentTreeOutput to 1

Tutorial

See the Libxslt Tutorial for an introduction to using the libxslt module.

Constants

Const XSLT_DEFAULT_URL:String
DescriptionThe XSLT "vendor" URL for this processor.

Const XSLT_DEFAULT_VENDOR:String
DescriptionThe XSLT "vendor" string for this processor.

Const XSLT_NAMESPACE:String
DescriptionThe XSLT specification namespace.

Const XSLT_PARSE_OPTIONS:Int
DescriptionThe set of options to pass to an xmlReadxxx when loading files for XSLT consumption.

Functions

Function xsltCleanupGlobals()
DescriptionUnregister all global variables set up by the XSLT library.

Types

Type TxsltCompMatch
DescriptionAn XSLT CompMatch.
Method free()
DescriptionFree up the memory allocated by all the elements of the CompMatch.
Method testCompMatchList:Int(context:TxsltTransformContext, node:TxmlNode)
Returns1 if it matches, 0 if it doesn't and -1 in case of failure.
DescriptionTest whether the node matches one of the patterns in the list.
InformationParameters:
  • context : an XSLT process context
  • node : a node
Function compilePattern:TxsltCompMatch(pattern:String, doc:TxmlDoc, node:TxmlNode, style:TxsltStylesheet, runtime:TxsltTransformContext)
ReturnsThe generated pattern list or Null in case of failure.
DescriptionCompile the XSLT pattern and generates a list of precompiled form suitable for fast matching.
InformationParameters:
  • pattern : an XSLT pattern
  • doc : the containing document
  • node : the containing element
  • style : the stylesheet
  • runtime : the transformation context, if done at run-time

Type TxsltDocument
DescriptionAn XSLT Document.
Method freeDocumentKeys()
DescriptionFree the keys associated to a document.
Function loadDocument:TxsltDocument(context:TxsltTransformContext , uri:String)
ReturnsThe new TxsltDocument or Null in case of error.
DescriptionTry to load a document (not a stylesheet) within the XSLT transformation context.
InformationParameters:
  • context : an XSLT transformation context
  • uri : the computed URI of the document
Function loadStyleDocument:TxsltDocument(style:TxsltStylesheet , uri:String)
ReturnsThe new TxsltDocument or Null in case of error.
DescriptionTry to load a stylesheet document within the XSLT transformation context.
InformationParameters:
  • style : an XSLT style sheet
  • uri : the computed URI of the document
Function newDocument:TxsltDocument(context:TxsltTransformContext, doc:TxmlDoc)
ReturnsThe new TxsltDocument.
DescriptionRegister a new document, apply key computations.
InformationParameters:
  • context : an XSLT transformation context (or Null)
  • doc : a parsed XML document
Function newStyleDocument:TxsltDocument(style:TxsltStylesheet, doc:TxmlDoc)
ReturnsThe new TxsltDocument.
DescriptionRegister a new document, apply key computations.
InformationParameters:
  • style : an XSLT style sheet
  • doc : a parsed XML document

Type TxsltElemPreComp
DescriptionAn XSLT ElemPreComp.
Method getType:Int()
DescriptionReturns the type of this elemement.
InformationThe following lists possible types:
Constant
XSLT_FUNC_COPY
XSLT_FUNC_SORT
XSLT_FUNC_TEXT
XSLT_FUNC_ELEMENT
XSLT_FUNC_ATTRIBUTE
XSLT_FUNC_COMMENT
XSLT_FUNC_PI
XSLT_FUNC_COPYOF
XSLT_FUNC_VALUEOF
XSLT_FUNC_NUMBER
XSLT_FUNC_APPLYIMPORTS
XSLT_FUNC_CALLTEMPLATE
XSLT_FUNC_APPLYTEMPLATES
XSLT_FUNC_CHOOSE
XSLT_FUNC_IF
XSLT_FUNC_FOREACH
XSLT_FUNC_DOCUMENT
XSLT_FUNC_WITHPARAM
XSLT_FUNC_PARAM
XSLT_FUNC_VARIABLE
XSLT_FUNC_WHEN
XSLT_FUNC_EXTENSION
Type TxsltTemplate
DescriptionAn XSLT Template.

Type TxsltStylesheet
DescriptionAn XSLT Stylesheet.
Method addKey:Int(name:String, nameURI:String, match:String, use:String, inst:TxmlNode)
Returns0 in case of success, and -1 in case of failure.
DescriptionAdd a key definition to the stylesheet.
InformationParameters:
  • name : the key name or Null
  • nameURI : the name URI or Null
  • match : the match value
  • use : the use value
  • inst : the key instruction
Method addTemplate:Int(cur:TxsltTemplate, mode:String, modeURI:String)
Returns-1 in case of error, 0 otherwise.
DescriptionRegister the XSLT pattern associated to cur.
InformationParameters:
  • cur : an XSLT template
  • mode : the mode name or Null
  • modeURI : the mode URI or Null
Method allocateExtra:Int()
ReturnsThe number of the slot.
DescriptionAllocate an extra runtime information slot statically while compiling the stylesheet and return its number.
Method applyStylesheet:TxmlDoc(doc:TxmlDoc)
ReturnsThe result document or Null in case of error.
DescriptionApply the stylesheet to the document.
InformationNOTE: This may lead to a non-wellformed output, XML wise !

Parameters:

  • doc : a parsed XML document

Method cleanupTemplates()
DescriptionCleanup the state of the templates used by the stylesheet and the ones it imports.
Method compileAttr(attr:TxmlAttribute)
DescriptionPrecompile an attribute in a stylesheet.
InformationBasically it checks if it is an attrubute value template, and if yes establish some structures needed to process it at transformation time.

Parameters:

  • attr : the attribute coming from the stylesheet

Method documentComp:TxsltElemPreComp(inst:TxmlNode)
ReturnsA precompiled data structure for the element.
DescriptionPre process an XSLT-1.1 document element.
InformationParameters:
  • inst : the instruction in the stylesheet
Method free()
DescriptionFree up the memory allocated to the sheet.
Method freeAttributeSetsHashes()
DescriptionFree up the memory used by attribute sets.
Method freeKeys()
DescriptionFree up the memory used by XSLT keys in the stylesheet.
Method freeNamespaceAliasHashes()
DescriptionFree up the memory used by namespaces aliases.
Method freeStyleDocuments()
DescriptionFree up all the space used by the loaded documents.
Method freeStylePreComps()
DescriptionFree up the memory allocated by all precomputed blocks.
Method freeTemplateHashes()
DescriptionFree up the memory used by addTemplate / getTemplate mechanism.
Method namespaceAlias(node:TxmlNode)
DescriptionRead the stylesheet-prefix and result-prefix attributes, register them as well as the corresponding namespace.
InformationParameters:
  • node : the xsl:namespace-alias node
Method nextImport:TxsltStylesheet()
ReturnsThe next stylesheet or Null if it was the last one.
DescriptionFind the next stylesheet in import precedence.
Method parseStylesheetAttributeSet(node:TxmlNode)
DescriptionParse an XSLT stylesheet attribute-set element.
InformationParameters:
  • node : the "attribute-set" element
Method parseStylesheetImport:Int(node:TxmlNode)
Returns0 in case of success -1 in case of failure.
DescriptionParse an XSLT stylesheet import element.
InformationParameters:
  • node : the import element
Method parseStylesheetInclude:Int(node:TxmlNode)
Returns0 in case of success -1 in case of failure.
DescriptionParse an XSLT stylesheet include element.
InformationParameters:
  • node : the include node
Method parseStylesheetOutput(node:TxmlNode)
DescriptionParse an XSLT stylesheet output element and record information related to the stylesheet output.
InformationParameters:
  • node : the "output" element
Method parseStylesheetProcess:TxsltStylesheet(doc:TxmlDoc)
Returnsthe value of the 'ret' parameter if everything went right, Null if something went amiss.
DescriptionParse the XSLT stylesheet adding the associated structures.
InformationParameters:
  • doc : an TxmlDoc parsed XML
Method parseTemplateContent(templ:TxmlNode)
Descriptionparse a template content-model Clean-up the template content from unwanted ignorable blank nodes and process xslt:text.
InformationParameters:
  • templ : the container node (can be a document for literal results)
Method resolveStylesheetAttributeSet()
DescriptionResolve the references between attribute sets.
Method saveResultToFilename:Int(url:String, res:TxmlDoc, compression:Int = 0)
ReturnsThe number of byte written or -1 in case of failure.
DescriptionSave the result res obtained by applying the stylesheet to a URL / filename.
InformationParameters:
  • url : a filename or URL
  • res : the result TxmlDoc
  • compression : the compression factor (0 - 9 inclusive)
Method stylePreCompute(inst:TxmlNode)
DescriptionPrecompute an XSLT stylesheet element.
InformationParameters:
  • inst : the instruction in the stylesheet
Function newStylesheet:TxsltStylesheet()
ReturnsThe new TxsltStylesheet or Null in case of error.
DescriptionCreate a new XSLT Stylesheet.
Function parseStylesheetDoc:TxsltStylesheet(doc:TxmlDoc)
ReturnsA new XSLT stylesheet structure.
DescriptionParse an XSLT stylesheet building the associated structures.
InformationParameters:
  • doc : an TxmlDoc parsed XML
Function parseStylesheetFile:TxsltStylesheet(filename:String)
ReturnsA new XSLT stylesheet structure.
DescriptionLoad and parse an XSLT stylesheet.
InformationParameters:
  • filename : the filename/URL to the stylesheet

Type TxsltTransformContext
DescriptionAn XSLT transformation context.
Method allocateExtraCtxt:Int()
Returnsthe number of the slot.
DescriptionAllocate an extra runtime information slot at run-time and return its number.
InformationThis makes sure there is a slot ready in the transformation context.
Method applyStripSpaces(node:TxmlNode)
DescriptionStrip the unwanted ignorable spaces from the input tree.
InformationParameters:
  • node : the root of the XML tree
Method attrListTemplateProcess:TxmlAttribute(target:TxmlNode, cur:TxmlAttribute)
ReturnsA new TxmlAttribute object, or Null in case of error.
DescriptionDo a copy of an attribute list with attribute template processing.
InformationParameters:
  • target : the element where the attributes will be grafted
  • cur : the first attribute
Method attrTemplateProcess:TxmlAttribute(target:TxmlNode, cur:TxmlAttribute)
ReturnsThe attribute replacement.
DescriptionProcess the given attribute and return the new processed copy.
InformationParameters:
  • target : the result node
  • cur : the attribute template node
Method attrTemplateValueProcess:String(value:String)
ReturnsThe computed string value or Null.
DescriptionProcess the given node and return the new string value.
InformationParameters:
  • value : the attribute template node value
Method attrTemplateValueProcessNode:String(value:String, node:TxmlNode)
ReturnsThe computed string value or Null.
DescriptionProcess the given string, allowing to pass a namespace mapping context and return the new string value.
InformationParameters:
  • value : the attribute template node value
  • node : the node hosting the attribute
Method createRVT:TxmlDoc()
ReturnsThe result value tree or Null in case of error.
DescriptionCreate a result value tree.
Method evalAttrValueTemplate:String(node:TxmlNode, name:String, namespace:String)
ReturnsThe computed string value or Null.
DescriptionEvaluate a attribute value template.
Informationi.e. the attribute value can contain expressions contained in curly braces ({}) and those are substituted by they computed value.

Parameters:

  • node : the stylesheet node
  • name : the attribute QName
  • namespace : the attribute namespace URI

Method evalAVT:String(avt:String, node:TxmlNode)
ReturnsThe computed string value or Null.
DescriptionProcess the given AVT, and return the new string value.
InformationParameters:
  • avt : the precompiled attribute value template info
  • node : the node hosting the attribute
Method evalStaticAttrValueTemplate:String(node:TxmlNode, name:String, namespace:String)
ReturnsThe static string value or Null.
DescriptionCheck if an attribute value template has a static value.
Informationi.e. the attribute value does not contain expressions contained in curly braces ({})

Parameters:

  • node : the stylesheet node
  • name : the attribute Name
  • namespace : the attribute namespace URI

Method evalTemplateString:String(node:TxmlNode, parent:TxmlNode)
ReturnsThe computed string value or Null.
DescriptionEvaluate a template string value.
Informationi.e. the parent list is interpreter as template content and the resulting tree string value is returned. This is needed for example by xsl:comment and xsl:processing-instruction.

Parameters:

  • node : the stylesheet node
  • parent : the content parent

Method evalXPathString:String(comp:TxmlXPathCompExpr)
ReturnsThe computed string value or Null.
DescriptionProcess the expression using XPath and get a string.
InformationParameters:
  • comp : the compiled XPath expression
Method findDocument:TxsltDocument(doc:TxmlDoc)
ReturnsThe desired xsltDocument or Null in case of error.
DescriptionTry to find a document within the XSLT transformation context.
InformationParameters:
  • doc : a parsed XML document
Method findElemSpaceHandling:Int(node:TxmlNode)
Returns1 if space should be stripped, 0 if not, and 2 if everything should be CDTATA wrapped.
DescriptionFind strip-space or preserve-space informations for an element respect the import precedence or the wildcards.
InformationParameters:
  • node : an XML node
Method findTemplate:TxsltTemplate(name:String, nameURI:String)
ReturnsThe TxsltTemplate or Null if not found.
DescriptionFinds the named template, apply import precedence rule.
InformationParameters:
  • name : the template name
  • nameURI : the template name URI
Method freeDocuments()
DescriptionFree up all the space used by the loaded documents.
Method freeRVTs()
DescriptionFree all the registered result value tree of the transformation.
Method getKey:TxmlNodeSet(name:String, nameURI:String, value:String)
ReturnsThe nodeset resulting from the query or Null.
DescriptionLookup a key.
InformationParameters:
  • name : the key name or Null
  • nameURI : the name URI or Null
  • value : the key value to look for
Method getNamespace:TxmlNs(curNode:TxmlNode, namespace:TxmlNs, out:TxmlNode)
ReturnsThe namespace node to use or Null.
DescriptionFind the right namespace value for this prefix.
InformationIf needed create and add a new namespace decalaration on the node Handle namespace aliases.

Parameters:

  • curNode : the input node
  • namespace : the namespace
  • out : the output node (or its parent)

Method getPlainNamespace:TxmlNs(curNode:TxmlNode, namespace:TxmlNs, out:TxmlNode)
ReturnsThe namespace node to use or Null.
DescriptionFind the right namespace value for this prefix.
InformationIf needed create and add a new namespace decalaration on the node Handle namespace aliases and make sure the prefix is not NULL, this is needed for attributes.

Parameters:

  • curNode : the input node
  • namespace : the namespace
  • out : the output node (or its parent)

Method getSpecialNamespace:TxmlNs(curNode:TxmlNode, uri:String, prefix:String, out:TxmlNode)
ReturnsThe namespace node to use or Null.
DescriptionFind the right namespace value for this URI.
InformationIf needed create and add a new namespace decalaration on the node.

Parameters:

  • curNode : the input node
  • uri : the namespace URI
  • prefic : the suggested prefix
  • out : the output node (or its parent)

Method getTemplate:TxsltTemplate(node:TxmlNode, style:TxsltStylesheet)
ReturnsThe xslt Template or Null if not found.
DescriptionFinds the template applying to this node.
InformationIf style is non-Null it means one needs to look for the next imported template in scope.

Parameters:

  • node : the node being processed
  • style : the current style

Method initKeys(doc:TxsltDocument)
DescriptionComputes all the keys tables for the current input document.
InformationShould be done before global varibales are initialized.

Parameters:

  • doc : an XSLT document

Method needElemSpaceHandling:Int()
Returns1 if space should be stripped, 0 if not.
DescriptionChecks whether that stylesheet requires white-space stripping.
Method registerPersistRVT:Int(rvt:TxmlDoc)
Returns0 in case of success and -1 in case of error.
DescriptionRegister the result value tree for destruction at the end of the processing.
InformationParameters:
  • rvt : a result value tree
Method registerTmpRVT:Int(rvt:TxmlDoc)
Returns0 in case of success and -1 in case of error.
DescriptionRegister the result value tree for destruction at the end of the context.
InformationParameters:
  • rvt : a result value tree
Method templateProcess:TxmlNode(node:TxmlNode)
ReturnsThe computed tree replacement.
DescriptionProcess the given node and return the new string value.
Function newTransformContext:TxsltTransformContext(stylesheet:TxsltStylesheet, doc:TxmlDoc)
ReturnsThe new xsltTransformContext or Null in case of error.
DescriptionCreate a new XSLT TransformContext.
InformationParameters:
  • stylesheet : a parsed XSLT stylesheet
  • doc : the input document

Module Information

Version1.01
LicenseMIT
AuthorDaniel Veillard
CreditAdapted for BlitzMax by Bruce A Henderson
ModserverBRL
History1.01
HistoryUpdated to Libxslt 1.1.20
History1.00 Initial Release (Libxslt 1.1.16)