xsl-list
[Top] [All Lists]

[xsl] Re: problem with fn:contains using xsl:param

2009-12-14 19:12:45
Date: Sun, 13 Dec 2009 17:40:44 -0500
From: "G. Ken Holman"<gkholman(_at_)CraneSoftwrights(_dot_)com>
Message-Id:<7(_dot_)0(_dot_)1(_dot_)0(_dot_)2(_dot_)20091213172539(_dot_)025d5598(_at_)wheresmymailserver(_dot_)com>

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

Right.

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()*">
     <type>xsd:date</type>
     <type>xsd:dateTime</type>
     <type>xsd:boolean</type>
    </xsl:param>
    ...
    <xsl:template match="xsd:element[(_at_)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:matching-substring>
      <xsl:if test="regex-group(1) eq $key">
        <xsl:value-of select="regex-group(2)"/>
      </xsl:if>   
    </xsl:matching-substring>
  </xsl:analyze-string>
</xsl:template>

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

<map>
  <entry key='foo' value='bar'/>
  (...)
</map>

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

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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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