[Home] [By Thread] [By Date] [Recent Entries]
At 2009-12-15 01:12 +0100, Piotr Dobrogost wrote:
Date: Sun, 13 Dec 2009 17:40:44 -0500 From: "G. Ken Holman"<gkholman@xxxxxxxxxxxxxxxxxxxx> Message-Id:<7.0.1.0.2.20091213172539.025d5598@xxxxxxxxxxxxxxxxxxxxxx> I use the pattern: contains(concat(' ',normalize-space($KnownXSDTypesMap),' '),
concat(' ',normalize-space(@type),' ')... where I can remove normalize-space() where I've been able to guarantee the string is properly formed. In XSLT 2 you might consider something like: Then I would change the above to (BTW, I changed it to a variable ... is it supposed to be parameterized from the invoking process?) the following sequence of elements which is not namespace-safe: <xsl:variable name="KnownXSDTypes" as="element()*">
<mapping from="xsd:date" to="DATE"/>
<mapping from="xsd:dateTime" to="DATETIME"/>
<mapping from="xsd:boolean" to="BOOL"/>
</xsl:variable>
...
<xsl:template match="xsd:element[@type=$KnownXSDTypes/@from]">
.... $KnownXSDTypes[@from=current()/@type]/@to ....or the following temporary tree, keeping in mind what Michael pointed out regarding namespace prefixes: <xsl:variable name="KnownXSDTypes" as="document-node()">
<xsl:document>
<mapping from="xsd:date" to="DATE"/>
<mapping from="xsd:dateTime" to="DATETIME"/>
<mapping from="xsd:boolean" to="BOOL"/>
</xsl:document>
</xsl:variable>
<xsl:key name="types" match="mapping" use="resolve-QName(@from,.)"/> <xsl:template match="xsd:element[key( 'types', resolve-QName(@type,.),
$KnownXSDTypes )]">
... key( 'types', resolve-QName(@type,.), $KnownXSDTypes )/@to ...
</xsl:template>I made generic map template which looks like this ... with maps looking like this That might be acceptable if you were obliged to pass the mapping as a string, but as you say that limits the characters available. ... And I saw you were willing to accept hard-wired namespace prefixes in your input XML ... I think this may be unwise ... I've noticed students of mine who have come to XSLT from XQuery prefer the prefix "xs" over "xsd" in their work. With this in mind, the approach I've used above using QNames is namespace-safe. For example, the above will work even if the input is: ...xmlns:xs="http://www.w3.org/2001/XMLSchema"> ... <xs:element type='xs:dateTime'>... I hope this helps. And thanks again to Mike regarding the use of QNames. . . . . . . . . . . . . Ken -- XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19 Vote for your XML training: http://www.CraneSoftwrights.com/s/i/ Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|

Cart



