Subject: Re: [xsl] What is the appropriate XPath 2.0 expression to reference an XSD simpleType ? From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 30 Dec 2015 05:01:47 -0000 |
Perhaps this can be used as a base for a shorter XSLT 2.0 solution (it will be possible to have a more compact XSLT 3.0 solution: <xsl:stylesheet version="2.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="my:my" exclude-result-prefixes="xs my"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="node()|@*" name="identity"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="xs:simpleType[last()]"> <xsl:call-template name="identity"/> <simpleType name="titleType" xmlns="http://www.w3.org/2001/XMLSchema"> <restriction base="{my:prefix(/*)}base"> <maxLength value="20" /> </restriction> </simpleType> </xsl:template> <xsl:function name="my:prefix" as="xs:string?"> <xsl:param name="pDocElem" as="element()"/> <xsl:sequence select=" for $tNS in $pDocElem/@targetNamespace/string(), $minLen in min($pDocElem/namespace::*[. eq $tNS]/string-length(name()) ), $pref in $pDocElem/namespace::* [. eq $tNS and string-length(name()) eq $minLen][1]/name() return concat($pref, ':'[$pref]) "/> </xsl:function> </xsl:stylesheet> On Tue, Dec 29, 2015 at 10:16 AM, Costello, Roger L. costello@xxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > 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> > > -- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- Never fight an inanimate object ------------------------------------- To avoid situations in which you might make mistakes may be the biggest mistake of all ------------------------------------ Quality means doing it right when no one is looking. ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play ------------------------------------- To achieve the impossible dream, try going to sleep. ------------------------------------- Facts do not cease to exist because they are ignored. ------------------------------------- Typing monkeys will write all Shakespeare's works in 200yrs.Will they write all patents, too? :) ------------------------------------- Sanity is madness put to good use. ------------------------------------- I finally figured out the only reason to be alive is to enjoy it.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] What is the appropriate X, Costello, Roger L. c | Thread | Re: [xsl] Need Math Help: How to Co, a kusa akusa8@xxxxxx |
Re: [xsl] Need Math Help: How to Co, a kusa akusa8@xxxxxx | Date | Re: [xsl] Need Math Help: How to Co, Eliot Kimber ekimber |
Month |