[xsl] XSLT validation with external file using Key

Subject: [xsl] XSLT validation with external file using Key
From: "Knight, Michel" <michel.knight@xxxxxxxx>
Date: Wed, 8 Jul 2009 15:36:24 -0400
Using Saxon 9
Windows
XSLT/XPATH version 2
--------------------------------------
Source File : student.htm
XSLT 		: testKey.xslt
XML 		: validated_data_test.xml   (Note My validation files as
over 2 000 possible values)

This XSLT goes and against an html file and use an XML file to validated
data.
This is workng nicely but it doesn't do everything I want.

It doesn't take care of (uppercase,White Space) so if one is
uppercase(HTML file) and it's lower-case in the XML(validation file)
it doesn't pick it up.

I've tried pluggin in normalize-space and lower-case with no success,
Your guidance would be appreciated.

Michel
----------------  student.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="http://www.w3.org/1999/xhtml"; lang="en" xml:lang="en">
<head>
<title>Student and Youth Programs - Jobs at Transport Canada - Transport
Canada</title>
<meta name="dc.subject" scheme="gccore" content="Student and Youth
Programs" />
<meta name="dc.subject" scheme="gccore" content="Crafts" />
</head>
<body>
</body>
</html>
----------------  testKey.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xhtml="http://www.w3.org/1999/xhtml";
exclude-result-prefixes="xhtml" >
<xsl:output method="xml" indent="yes" encoding="windows-1252"
exclude-result-prefixes="xhtml" ></xsl:output>
<xsl:strip-space elements="*"/>

<xsl:key name="keyrefname" match="ref" use="."/>
	<xsl:template match="xhtml:html" exclude-result-prefixes="xhtml"
>
	<root>
	<metadata>
			<xsl:apply-templates select="//xhtml:meta"/>
		</metadata>
	</root>
	</xsl:template>

	<xsl:template match="//xhtml:meta">
		<xsl:if test="@scheme = 'gccore'">
		<xsl:variable name="keyref" select="@content" />
		    <xsl:for-each
select="document('validated_data_test.xml')/root">
			<xsl:choose>
				 <xsl:when
test="empty(key('keyrefname',$keyref))">
					   <!-- Error validation not
found in file validated_data_test.xml, so print empty content -->
					   <content></content>
				 </xsl:when>
				 <xsl:otherwise>
					<!-- Good content So get current
value as it is -->

					<content><xsl:value-of
select="$keyref" /></content>
				 </xsl:otherwise>
		  	</xsl:choose>
		</xsl:for-each>
	        </xsl:if>
	</xsl:template>
</xsl:stylesheet>
----------------  validated_data_test.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
	<ref>Architectural heritage</ref>
	<ref>Crafts</ref>
	<ref>Artisanat</ref>
	<ref>Cattle</ref>
</root>

Current Thread