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

Re: problem with fn:contains using xsl:param

Subject: Re: problem with fn:contains using xsl:param
From: Piotr Dobrogost <pd@xxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 15 Dec 2009 01:12:02 +0100
 Re: problem with fn:contains using xsl:param
Date: Sun, 13 Dec 2009 17:40:44 -0500
From: "G. Ken Holman"<gkholman@xxxxxxxxxxxxxxxxxxxx>

First "xsd:bool" is incomplete and would have to be "xsd:boolean".


And while it won't affect this particular example, the "protected"
way of doing what you are doing with strings is to add a space at the
start and end of your string with the tokens, and then add a space to
the start and end of the token being searched.

Right. It does effect my example as xsd:date is a substring of xsd:dateTime. How can I add a space before and after @type in
<xsl:template match="xsd:element[contains($KnownXSDTypesMap, @type)]"> statement?
I tried ' @type ' but it doesn't work. Putting, as a test, single quotes around @type like this '@type' does not work either what would suggest that @type is treated literally when quoted in such a way.

In XSLT 2 you might consider something like:

    <xsl:param name="KnownXSDTypes" as="element()*">
    <xsl:template match="xsd:element[@type=$KnownXSDTypes]">

Very nice. It solves problem from my original post.

However, I really need two things;
1. test if a value of a type attribute is on the list
2. if it's on that list I need to map it to some predefined string being used later.
Your idea solves the first problem but I still need to solve the second one. And the best solution would be to use a map to solve both problems at the same time. Do you agree?

I made generic map template which looks like this

<xsl:template name="KeyToValue">
  <xsl:param name="map"/>
  <xsl:param name="key"/>
  <xsl:analyze-string select="$map" regex="([^\s]+)/([^\s]+)">
      <xsl:if test="regex-group(1) eq $key">
        <xsl:value-of select="regex-group(2)"/>

with maps looking like this

<xsl:param name="KnownXSDTypesMap">xsd:date/DATE xsd:dateTime/DATETIME xsd:boolean/BOOL</xsl:param>

It works but you can't have slash sign ('/') in neither key nor value. That's the problem with encoding a map as a string. One would have to use xml elements for this to be truly generic. Something like

  <entry key='foo' value='bar'/>

but I don't know how to include and use definition such as this one in my xsl file? Further, how to extract all keys and make a set out of them the same way you showed for xsl:param?

Thanks for your answer and time.

Regards Piotr Dobrogost

Yes, I saw Michael's reply but wanted to extend the scope of my original question while replying to your post.

Current Thread


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.
First Name
Last Name
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.