Subject: Re: [xsl] XSL String Mapping Problem. From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Wed, 10 Dec 2008 09:18:13 -0500 |
Hello,
I am looking for a very nice mapper "Design Pattern".
I used the XML/XSL snippet below. However the "@key eq ." seems not to work.
If I introduce a variable it works fine:
<xsl:variable name="var" select="."/> <xsl:value-of select="$map[@key eq $var]/@val"/>
Questions:
1. How to get this mapper working without variable?
T:\ftemp>type jos1.xsl <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:variable name="map" as="element()+"> <elem key="key1" val="value1"/> <elem key="key2" val="value2"/> <elem key="key3" val="value3"/> </xsl:variable> <xsl:template match="demos/demo"> Found key: <xsl:value-of select="."/> Corresponding value: <xsl:value-of select="$map[@key eq current()]/@val"/> <br/> </xsl:template> </xsl:stylesheet>
T:\ftemp>xslt2 jos.xml jos1.xsl <?xml version="1.0" encoding="UTF-8"?>
Found key: key1 Corresponding value: value1<br/>
Found key: key2 Corresponding value: value2<br/>
2. What is the the 'defacto XPath standard' for mapping a list hardcoded keys to hardcoded values?
T:\ftemp>type jos2.xsl <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:variable name="map"> <elem key="key1" val="value1"/> <elem key="key2" val="value2"/> <elem key="key3" val="value3"/> </xsl:variable> <xsl:key name="mapkey" match="elem" use="@key"/> <xsl:template match="demos/demo"> Found key: <xsl:value-of select="."/> Corresponding value: <xsl:value-of select="key('mapkey',.,$map)/@val"/> <br/> </xsl:template> </xsl:stylesheet>
T:\ftemp>xslt2 jos.xml jos2.xsl <?xml version="1.0" encoding="UTF-8"?>
Found key: key1 Corresponding value: value1<br/>
Found key: key2 Corresponding value: value2<br/>
-- Upcoming XSLT/XSL-FO, UBL and code list hands-on training classes: : Sydney, AU 2009-01/02; Brussels, BE 2009-03; Prague, CZ 2009-03 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSL String Mapping Proble, Michael Kay | Thread | [xsl] key from one file to another , Ganesh Babu N |
RE: [xsl] key from one file to anot, Michael Kay | Date | [xsl] [ANN] XML Prague 2009 Registr, Jim Fuller |
Month |