xsl-list
[Top] [All Lists]

Re: [xsl] XSLT program that generates XSD, the XSD has a pattern facet, the regex has curly braces, the curly braces are causing me trouble

2017-07-19 08:11:22
At 2017-07-19 12:45 +0000, Costello, Roger L. costello(_at_)mitre(_dot_)org 
wrote:
I am writing an XSLT program that outputs an XML Schema.

The generated XML Schema is to contain a simpleType, with a pattern facet. Its regex is to express: zero or more lowercase letters of the English alphabet, the left curly brace, and the right curly brace:

<xs:simpleType name="Stuff">
    <xs:restriction base="xs:string">
        <xs:pattern value="[a-z\{\}]*" />
    </xs:restriction>
</xs:simpleType>

The curly braces are special symbols in the regex language, so I escaped them: \{ and \}

Interestingly, the curly braces are also special symbols in the XSLT language. That's causing me problems.

Below is my XSLT program. It doesn't work - an error is generated because of the curly braces.

Because they are for an attribute value template in an attribute specification.

Note that replacing the curly braces with their character references also failed:

<xs:pattern value="[a-z\&#x7B;\ &#x7D;]*" />

Because XSD doesn't care what syntax is used in the stylesheet for the characters to be used in the logic.

What's the right way to do this?

Double them up:

<xs:restriction base="xs:string">
    <xs:pattern value="[a-z\{{\}}]*" />
</xs:restriction>

I hope this helps.

. . . . .  Ken

p.s. my XSLT and XSL-FO books are now available for free on my web site.

--
Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/s/ |
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Streaming hands-on XSLT/XPath 2 training class @ US$45 (5 hours free) |
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>