Node attr pair removal for n:attr
node.xsl (n:attr): added node.xsl: removed all attr-pairs record.xsl: updated n:element callsmaster
parent
e8e2dff3e6
commit
057cdbb683
95
src/node.xsl
95
src/node.xsl
|
@ -2,7 +2,7 @@
|
||||||
<!--@comment
|
<!--@comment
|
||||||
Node constructors
|
Node constructors
|
||||||
|
|
||||||
Copyright (C) 2015 Mike Gerwitz
|
Copyright (C) 2015, 2016 Mike Gerwitz
|
||||||
|
|
||||||
This file is part of hoxsl.
|
This file is part of hoxsl.
|
||||||
|
|
||||||
|
@ -48,7 +48,6 @@
|
||||||
|
|
||||||
@menu
|
@menu
|
||||||
* Primitive Constructors:: Functional equivalents of XSLT node primitives
|
* Primitive Constructors:: Functional equivalents of XSLT node primitives
|
||||||
* Private Functions:Node Private Functions. Internal details
|
|
||||||
@end menu
|
@end menu
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,8 +61,8 @@
|
||||||
@float Figure, fig:node-primitive
|
@float Figure, fig:node-primitive
|
||||||
@verbatim
|
@verbatim
|
||||||
<sequence select="n:element( QName( 'ns', 'foo' ),
|
<sequence select="n:element( QName( 'ns', 'foo' ),
|
||||||
( QName( 'ns', 'attr1' ), 'value1',
|
( n:attr( QName( 'ns', 'attr1' ), 'value1' ),
|
||||||
QName( 'ns', 'attr2' ), 'value2' ),
|
n:attr( QName( 'ns', 'attr2' ), 'value2' ) ),
|
||||||
( n:text( 'Nest to create trees' ),
|
( n:text( 'Nest to create trees' ),
|
||||||
n:comment( 'functional nodes' ),
|
n:comment( 'functional nodes' ),
|
||||||
n:element( QName( 'ns', 'bar' ) ) ) )" />
|
n:element( QName( 'ns', 'bar' ) ) ) )" />
|
||||||
|
@ -85,26 +84,20 @@
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Construct an element named @var{qname} with attributes defined by
|
Construct an element named @var{qname} with attributes @var{attrs} and
|
||||||
the QName-value pairs @var{attr-pairs} and child nodes @var{children}. An
|
child nodes @var{children}. An empty sequence may be provided if no
|
||||||
empty sequence may be provided if no attributes or children are desired
|
attributes or children are desired (see also the @ref{n:element#1,,unary}
|
||||||
(see also the @ref{n:element#1,,unary} and @ref{n:element#2,,binary}
|
and @ref{n:element#2,,binary} overloads).
|
||||||
overloads).
|
|
||||||
|
|
||||||
For QName-value pair @var{attr-pairs}, @math{2n} will always be considered
|
|
||||||
to be a QName and @math{2n+1} its associated value. If the final value in
|
|
||||||
the attribute pair sequence is missing, then it will result in an
|
|
||||||
attribute with an empty string as its value.
|
|
||||||
-->
|
-->
|
||||||
<function name="n:element" as="element()">
|
<function name="n:element" as="element()">
|
||||||
<param name="qname" as="xs:QName" />
|
<param name="qname" as="xs:QName" />
|
||||||
<param name="attr-pairs" as="item()*" />
|
<param name="attrs" as="attribute()*" />
|
||||||
<param name="child-nodes" as="node()*" />
|
<param name="child-nodes" as="node()*" />
|
||||||
|
|
||||||
<variable name="element" as="element()">
|
<variable name="element" as="element()">
|
||||||
<element name="{$qname}"
|
<element name="{$qname}"
|
||||||
namespace="{namespace-uri-from-QName( $qname ) }">
|
namespace="{namespace-uri-from-QName( $qname ) }">
|
||||||
<sequence select="_n:attr-from-pair( $attr-pairs ),
|
<sequence select="$attrs,
|
||||||
$child-nodes" />
|
$child-nodes" />
|
||||||
</element>
|
</element>
|
||||||
</variable>
|
</variable>
|
||||||
|
@ -114,19 +107,18 @@
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Construct an element named @var{qname} with attributes defined by
|
Construct an element named @var{qname} with attributes @var{attrs} and no
|
||||||
the QName-value pairs @var{attr-pairs} and no child nodes. An empty
|
child nodes. An empty sequence may be provided if no attributes are
|
||||||
sequence may be provided if no attributes are desired (see also the
|
desired (see also the @ref{n:element#1,,unary} overload).
|
||||||
@ref{n:element#1,,unary} overload).
|
|
||||||
|
|
||||||
This is equivalent to @code{n:element( $qname, $attr-pairs, () )}; see
|
This is equivalent to @code{n:element( $qname, $attrs, () )}; see
|
||||||
@ref{n:element#3}.
|
@ref{n:element#3}.
|
||||||
-->
|
-->
|
||||||
<function name="n:element" as="element()">
|
<function name="n:element" as="element()">
|
||||||
<param name="qname" as="xs:QName" />
|
<param name="qname" as="xs:QName" />
|
||||||
<param name="attr-pairs" as="item()*" />
|
<param name="attrs" as="attribute()*" />
|
||||||
|
|
||||||
<sequence select="n:element( $qname, $attr-pairs, () )" />
|
<sequence select="n:element( $qname, $attrs, () )" />
|
||||||
</function>
|
</function>
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,6 +134,28 @@
|
||||||
<sequence select="n:element( $qname, () )" />
|
<sequence select="n:element( $qname, () )" />
|
||||||
</function>
|
</function>
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Construct an attribute named @var{qname} with the value @var{value}.
|
||||||
|
-->
|
||||||
|
<function name="n:attr" as="attribute()">
|
||||||
|
<param name="qname" as="xs:QName" />
|
||||||
|
<param name="value" as="xs:anyAtomicType" />
|
||||||
|
|
||||||
|
<!-- some trickery (if there's a better way, lmk) -->
|
||||||
|
<variable name="tmp-container" as="element()">
|
||||||
|
<element name="tmp">
|
||||||
|
<attribute name="{$qname}"
|
||||||
|
namespace="{namespace-uri-from-QName( $qname ) }"
|
||||||
|
select="$value" />
|
||||||
|
</element>
|
||||||
|
</variable>
|
||||||
|
|
||||||
|
<!-- there will only be one -->
|
||||||
|
<sequence select="$tmp-container/@*" />
|
||||||
|
</function>
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Create a text node with the given @var{text}. The @var{text} will be
|
Create a text node with the given @var{text}. The @var{text} will be
|
||||||
output verbatim without any whitespace processing.
|
output verbatim without any whitespace processing.
|
||||||
|
@ -171,39 +185,4 @@
|
||||||
<sequence select="$comment" />
|
<sequence select="$comment" />
|
||||||
</function>
|
</function>
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
@node Node Private Functions
|
|
||||||
@section Private Functions
|
|
||||||
These functions support the various node functions, but should not be used
|
|
||||||
outside of Hoxsl itself.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Construct attributes from a list of QName-value pairs.
|
|
||||||
|
|
||||||
For more information on the pair format, see @ref{n:element#3}.
|
|
||||||
-->
|
|
||||||
<function name="_n:attr-from-pair" as="attribute()*">
|
|
||||||
<param name="attr-pairs" as="item()*" />
|
|
||||||
|
|
||||||
<variable name="attribute" as="attribute()">
|
|
||||||
<variable name="qname" as="xs:QName"
|
|
||||||
select="$attr-pairs[ 1 ]" />
|
|
||||||
<variable name="value" as="xs:anyAtomicType?"
|
|
||||||
select="$attr-pairs[ 2 ]" />
|
|
||||||
|
|
||||||
<attribute name="{$qname}"
|
|
||||||
namespace="{namespace-uri-from-QName( $qname ) }"
|
|
||||||
select="$value" />
|
|
||||||
</variable>
|
|
||||||
|
|
||||||
<sequence select="if ( exists( $attr-pairs ) ) then
|
|
||||||
( $attribute,
|
|
||||||
_n:attr-from-pair(
|
|
||||||
subsequence( $attr-pairs, 3 ) ) )
|
|
||||||
else
|
|
||||||
()" />
|
|
||||||
</function>
|
|
||||||
|
|
||||||
</stylesheet>
|
</stylesheet>
|
||||||
|
|
|
@ -281,7 +281,8 @@
|
||||||
select="max( ( $slots, $super-slots ) )" />
|
select="max( ( $slots, $super-slots ) )" />
|
||||||
|
|
||||||
<sequence select="n:element( $R:qname,
|
<sequence select="n:element( $R:qname,
|
||||||
( QName( $_R:ns, 'slots' ), $slot-count ),
|
( n:attr( QName( $_R:ns, 'slots' ),
|
||||||
|
$slot-count ) ),
|
||||||
( $Supertype/node(),
|
( $Supertype/node(),
|
||||||
n:element( $qname ) ) )" />
|
n:element( $qname ) ) )" />
|
||||||
</function>
|
</function>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<!--
|
<!--
|
||||||
Tests node constructors
|
Tests node constructors
|
||||||
|
|
||||||
Copyright (C) 2015 Mike Gerwitz
|
Copyright (C) 2015, 2016 Mike Gerwitz
|
||||||
|
|
||||||
This file is part of hoxsl.
|
This file is part of hoxsl.
|
||||||
|
|
||||||
|
@ -79,9 +79,9 @@
|
||||||
<call function="n:element">
|
<call function="n:element">
|
||||||
<param name="qname" select="$test-qname-b" />
|
<param name="qname" select="$test-qname-b" />
|
||||||
|
|
||||||
<param name="attr-pairs"
|
<param name="attrs"
|
||||||
select="( $test-qname-a, 'a',
|
select="( n:attr( $test-qname-a, 'a' ),
|
||||||
$test-qname-c, 'c' )" />
|
n:attr( $test-qname-c, 'c' ) )" />
|
||||||
</call>
|
</call>
|
||||||
|
|
||||||
<expect label="produces an element"
|
<expect label="produces an element"
|
||||||
|
@ -106,23 +106,10 @@
|
||||||
</scenario>
|
</scenario>
|
||||||
|
|
||||||
|
|
||||||
<scenario label="with an attribute missing a value">
|
|
||||||
<call function="n:element">
|
|
||||||
<param name="qname" select="$test-qname-b" />
|
|
||||||
|
|
||||||
<param name="attr-pairs"
|
|
||||||
select="( $test-qname-a )" />
|
|
||||||
</call>
|
|
||||||
|
|
||||||
<expect label="produces an attribute with an empty string value"
|
|
||||||
test="$x:result/@test-prefix-a:a = ''" />
|
|
||||||
</scenario>
|
|
||||||
|
|
||||||
|
|
||||||
<scenario label="with child nodes">
|
<scenario label="with child nodes">
|
||||||
<call function="n:element">
|
<call function="n:element">
|
||||||
<param name="qname" select="$test-qname-b" />
|
<param name="qname" select="$test-qname-b" />
|
||||||
<param name="attr-pairs" select="()" />
|
<param name="attrs" select="()" />
|
||||||
|
|
||||||
<param name="child-nodes"
|
<param name="child-nodes"
|
||||||
select="$test-node-element,
|
select="$test-node-element,
|
||||||
|
@ -164,7 +151,7 @@
|
||||||
<scenario label="within an element">
|
<scenario label="within an element">
|
||||||
<call function="n:element">
|
<call function="n:element">
|
||||||
<param name="name" select="QName( '', 'foo' )" />
|
<param name="name" select="QName( '', 'foo' )" />
|
||||||
<param name="attr-pairs" select="()" />
|
<param name="attrs" select="()" />
|
||||||
|
|
||||||
<param name="child-nodes"
|
<param name="child-nodes"
|
||||||
select="n:comment( $test-text-a ),
|
select="n:comment( $test-text-a ),
|
||||||
|
@ -184,6 +171,23 @@
|
||||||
</scenario>
|
</scenario>
|
||||||
|
|
||||||
|
|
||||||
|
<scenario label="A new attribute">
|
||||||
|
<!-- to test this, the attribute needs an element parent -->
|
||||||
|
<call function="n:element">
|
||||||
|
<param name="qname" select="$test-qname-a" />
|
||||||
|
<param name="attrs"
|
||||||
|
select="n:attr( $test-qname-b, 'foo' )" />
|
||||||
|
<param name="child-nodes" select="()" />
|
||||||
|
</call>
|
||||||
|
|
||||||
|
<expect label="has given QName"
|
||||||
|
test="node-name( $x:result/@* ) = $test-qname-b" />
|
||||||
|
|
||||||
|
<expect label="has given value"
|
||||||
|
test="$x:result/@* = 'foo'" />
|
||||||
|
</scenario>
|
||||||
|
|
||||||
|
|
||||||
<scenario label="A new text node">
|
<scenario label="A new text node">
|
||||||
<scenario label="standalone">
|
<scenario label="standalone">
|
||||||
<call function="n:text">
|
<call function="n:text">
|
||||||
|
@ -201,7 +205,7 @@
|
||||||
<scenario label="adjacent to text within an element">
|
<scenario label="adjacent to text within an element">
|
||||||
<call function="n:element">
|
<call function="n:element">
|
||||||
<param name="name" select="QName( '', 'foo' )" />
|
<param name="name" select="QName( '', 'foo' )" />
|
||||||
<param name="attr-pairs" select="()" />
|
<param name="attrs" select="()" />
|
||||||
|
|
||||||
<param name="child-nodes"
|
<param name="child-nodes"
|
||||||
select="n:text( $test-text-a ),
|
select="n:text( $test-text-a ),
|
||||||
|
@ -221,7 +225,7 @@
|
||||||
<scenario label="separated by other nodes within an element">
|
<scenario label="separated by other nodes within an element">
|
||||||
<call function="n:element">
|
<call function="n:element">
|
||||||
<param name="name" select="QName( '', 'foo' )" />
|
<param name="name" select="QName( '', 'foo' )" />
|
||||||
<param name="attr-pairs" select="()" />
|
<param name="attrs" select="()" />
|
||||||
|
|
||||||
<param name="child-nodes"
|
<param name="child-nodes"
|
||||||
select="n:text( $test-text-a ),
|
select="n:text( $test-text-a ),
|
||||||
|
|
Loading…
Reference in New Issue