RE: [xsl] first question to the list: contains

Subject: RE: [xsl] first question to the list: contains
From: "Jared Stein" <STEINJA@xxxxxxxx>
Date: Fri, 02 Nov 2007 23:22:32 -0600
Scott, thanks for the great explanation.  Though it's disappointing (as
I need to check for _any_ Japanese character to make this test
effective), at least it makes sense. 

Luckily, it's not out of the question for me to add an additional
element or attribute to the XML files--this is something I could do
pretty easily with a search and replace, and would in fact add to the
value of the XML.

Date: Fri, 2 Nov 2007 17:39:29 -0500
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
From: "Scott Trenda" <Scott.Trenda@xxxxxxxx>
Subject: RE: [xsl] first question to the list: contains
Message-ID:
<DA088AB42E20F841A1CDBDD0564B8E2D0530136D@xxxxxxxxxxxxxxxxxxxx>

The problem here is that XSLT operates on the expanded infoset of the
parsed XML file, and is blind to the literal text that created that
infoset. That is, if your XML file includes those characters (e.g.
<wording>123&#12360;456</wording>), then your XSLT won't see the
entity's literal text (&amp;#12360;), it'll see that entity's value
(the
Japanese character). Likewise, if you use an entity in your XSLT
stylesheet, then the processor will use the value of that entity,
rather
than the text you used to represent it.

So, if you know the characters that you need to check for, you can do
something like this:
<xsl:if test=3D"translate(wording,
'&#12360;&#12361;&#12362;&#12363;&#12364;&#12365;&#12366;&#12367;&#12368
;&#12369;&#12370;&#12371;&#12372;&#12373;', '') !=3D string(wording)">
	<xsl:attribute name=3D"class">
		<xsl:text>fs front jpns</xsl:text>
	</xsl:attribute>
</xsl:if>

This test just wipes out the numerals in question, and checks to see
if
its string-value is any different than before.

I guessed at the entity code numbers here - you'll have to look up
their
actual ones and substitute them in. If you're checking for Japanese
numerals, I'm guessing you can narrow the check down to ichi
(&#12360;),
ni (&#12361;), san (&#12362;), yon (&#12363;), go (&#12364;), roku
(&#12365;), shichi (&#12366;), hachi (&#12367;), kyuu (&#12368;), juu
(&#12369;), hyaku (&#12370;), sen (&#12371;), man (&#12372;), and oku
(&#12373;).

~ Scott

Jared Stein

   Director of Instructional Design Services
   Utah Valley State College, MS 149
 
Teaching w/ Technology Idea Exchange 2008: The Open Conference
   Submit your presentation proposal now! http://www.ttix.org

Current Thread