Skip to content

xsl:xpath instruction #2004

@michaelhkay

Description

@michaelhkay

In the case study #1786 (comment) I encountered a use case where an instruction xsl:xpath would be useful.

<xsl:xpath>
   { "class":
       { "name": f:degenerify(name/@identifier),
          "abstract": ? abstract,
           "extends": array{? extendedTypes =!> map:merge(apply-templates()) },
           "implements": array{? implementedTypes =!> map:merge(apply-templates()) }
             ...
       }
  }
 </xsl:xpath>

The instruction is very simple: <xsl:xpath>EXPR</xsl:xpath> is equivalent to <xsl:sequence select="EXPR"/>. It's particularly useful because XPath constructors for maps and arrays are so much more concise than the XSLT equivalents. Compared with using xsl:sequence, it means that:

  • XML attribute value normalization doesn't kick in, so your formatting is better protected (meaning also that the system has some chance of computing line numbers correctly for diagnostics)
  • You haven't tied up either single or double-quotes as an attribute delimiter; both can be freely used within the expression.
  • You aren't creating the false impression that you're returning a (multi-item) sequence

Note that the content is NOT a sequence constructor; no child elements are allowed; and the content is not interpreted as a text value template. Unlike xsl:evaluate, the XPath expression is statically fixed.

(This example also introduces apply-templates as a function, but that will be a separate proposal).

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureA change that introduces a new featurePR PendingA PR has been raised to resolve this issueXSLTAn issue related to XSLT

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions