[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: What is the appropriate XPath 2.0 expression to r

Subject: Re: What is the appropriate XPath 2.0 expression to reference an XSD simpleType ?
From: "Costello, Roger L. costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 29 Dec 2015 18:16:31 -0000
Re:  What is the appropriate XPath 2.0 expression to  r
Dan Sullivan wrote:

> Are you looking for something like
>
> *[local-name()='base' and (namespace-uri()='' or
namespace-uri()='http://www.w3.org/2001/XMLSchema']

That is a good suggestion Dan. Thank you. However, that XPath returns a
simpleType not a QName (which is what I desire).

I wrote an XSLT program which returns the appropriate QName. See below. It is
awful (i.e., it is a very complicated solution to a very simple problem). I am
hoping that someone can provide a simple solution.  /Roger

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                        xmlns:g="function"
                        xmlns:xs="http://www.w3.org/2001/XMLSchema"
                       exclude-result-prefixes="#all"
                       version="2.0">

    <xsl:output method="text" />

    <xsl:template match="xs:schema">
        <xsl:message>
            <xsl:text>The appropriate prefix:local-name is: #</xsl:text>
            <xsl:value-of select="g:QName-for-local-name('base', .)"/>
            <xsl:text>#</xsl:text>
        </xsl:message>
    </xsl:template>

    <xsl:function name="g:QName-for-local-name">
        <xsl:param name="local-name" as="xs:string" />
        <xsl:param name="schema" as="element(xs:schema)" />

        <xsl:variable name="tns" select="$schema/@targetNamespace"
as="xs:anyURI?"/>

        <xsl:variable name="prefix" select="g:namespace-prefix-for-uri($tns,
$schema)" as="xs:string?"/>
        <xsl:choose>
            <xsl:when test="not($tns)">
                <xsl:value-of select="QName('', $local-name)"/>
            </xsl:when>
            <xsl:when test="not($prefix)">
                <xsl:value-of select="QName($tns, $local-name)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="QName($tns, concat($prefix, ':',
$local-name))"/>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:function>

    <xsl:function name="g:namespace-prefix-for-uri" as="xs:string?">
        <xsl:param name="uri" as="xs:anyURI?" />
        <xsl:param name="schema" as="element(xs:schema)" />

        <xsl:choose>
            <xsl:when test="not($uri)" />
            <xsl:otherwise>
                <xsl:variable name="prefixes"
select="in-scope-prefixes($schema)"/>
                <xsl:value-of
select="g:auxiliary-namespace-prefix-for-uri($uri, $prefixes, $schema)"/>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:function>

    <xsl:function name="g:auxiliary-namespace-prefix-for-uri"
as="xs:string?">
        <xsl:param name="uri" as="xs:anyURI" />
        <xsl:param name="prefixes" as="xs:string*" />
        <xsl:param name="schema" as="element(xs:schema)" />

        <xsl:choose>
            <xsl:when test="count($prefixes) eq 0" />
            <xsl:when test="namespace-uri-for-prefix($prefixes[1], $schema) eq
$uri">
                <xsl:value-of select="$prefixes[1]"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of
select="g:auxiliary-namespace-prefix-for-uri($uri, $prefixes[position() gt 1],
$schema)"/>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:function>

</xsl:stylesheet>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.