namespace-alias
The namespace-alias statement provides a means of mapping a namespace used in a stylesheet onto another,
different, namespace in the output tree. It is provded in Rexsel for completeness but would never normally be used, for the reason below.
Syntax
<namespace-alias> ::= “namespace-alias”
“map-from” <quote> <name> <quote>
“to” <quote> <name> <quote>
Options
map-from
|
the namespace that is being mapped from. |
to
|
the namespace that is being mapped to. |
Elements
None.
Examples
It is rarely used except in the cases where a new stylesheet is generated from within another. Within Rexsel this is not used since it
does not support "naked" elements. For example, consider the XSLT for producing another XSLT stylesheet.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:nxsl="nxsl.xsl">
<xsl:param name="inputName">name</xsl:param>
<xsl:param name="inputValue">value</xsl:param>
<xsl:namespace-alias stylesheet-prefix="nxsl" result-prefix="xsl"/>
<xsl:template match="/">
<nxsl:stylesheet version="1.0">
<nxsl:variable name="{$inputName}">
<nxsl:value-of select="{$inputValue}"/>
</nxsl:variable>
</nxsl:stylesheet>
</xsl:template>
</xsl:stylesheet>
This would produce a new stylesheet
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="name">
<xsl:value-of select="value"/>
</xsl:variable>
</xsl:stylesheet>
As indicated this would be impossible to directly encode into Rexsel. However the following would give the same effect.
stylesheet {
version "1.0"
parameter inputName "name"
parameter inputValue "value"
match using "/" {
element "xsl:stylesheet" {
attribute "version" "1.0"
element "xsl:variable" {
attribute "name" { value "$inputName" }
element "xsl:value-of" {
attribute "select" { value "$inputValue" }
}
}
}
}
}
As would the slightly more correct version.
stylesheet {
version "1.0"
parameter inputName "name"
parameter inputValue "value"
match using "/" {
element "stylesheet" namespace "http://www.w3.org/1999/XSL/Transform" {
attribute "version" "1.0"
element "variable" namespace "http://www.w3.org/1999/XSL/Transform" {
attribute "name" { value "$inputName" }
element "value-of" namespace "http://www.w3.org/1999/XSL/Transform" {
attribute "select" { value "$inputValue" }
}
}
}
}
}
In all both cases the new stylesheet would be.
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
<variable name="name">
<value-of select="blank"/>
</variable>
</stylesheet>
Errors
No name for map-from.
stylesheet {
version "1.0"
xmlns "pxsl" "https://paloose.org.uk/stylesheets.xsl"
namespace-alias map-from to "xsl"
match using "/" {
}
}
will give the error
**** (118) "using" required in element "match" in line 4
Insert element.
Leaving out an expression for scope or other option.
match using ”//concertList“ scope {
element "div" {
attribute "id" "concertListAndIndex"
element "span" {
attribute "class" "code-dir"
text "<"
apply-templates scope "inline-text"
text ">"
}
}
}
gives
**** (106) Unexpected symbol "to" instead of "'map-from' name" in line 6
Check spelling, missing expression, bracket or quote?
**** (119) Missing item map expression in line 6
Insert item.
Similarly with neither present:
match using ”//concertList“ scope {
element "div" {
attribute "id" "concertListAndIndex"
element "span" {
attribute "class" "code-dir"
text "<"
apply-templates scope "inline-text"
text ">"
}
}
}
will give
**** (106) Unexpected symbol "to" instead of "'map-from' name" in line 6
Check spelling, missing expression, bracket or quote?
**** (106) Unexpected symbol "match" instead of "'to' name" in line 6
Check spelling, missing expression, bracket or quote?
**** (119) Missing item map expression in line 6
Insert item.
Copyright 2024 Hugh Field-Richards. All Rights Reserved.