Jump to content

Trouble With Namspaces In Xslt


Grasslands

Recommended Posts

Hi. I have some XML which I am trying to transform. The XML has namespaces,and I cannot seem to find the nodes while transforming with my xslt. XML sample

<?xml version="1.0" encoding="UTF-8"?><Message xsi:schemaLocation="http://www.theia.org.uk/ILR/2011-12/1 ILR-2011-12-Structure.xsd"		 xmlns="http://www.theia.org.uk/ILR/2011-12/1"		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  <Header>	<CollectionDetails>	  <Collection>ILR</Collection>	  <Year>1112</Year>	  <FilePreparationDate>2011-10-21</FilePreparationDate>	</CollectionDetails>  </Header></Message>

XSL

<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> --><?xmls version "1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:t="http://www.theia.org.uk/ILR/2011-12/1"				xmlns:xsl="http://www.w3.org/1999/XSL/Transform"				xmlns="http://www.w3.org/2001/XMLSchema-instance"				xmlns:xslFormatting="urn:xslFormatting">  <xsl:output method="html" indent="no"/>  <xsl:template match="/t:Message">	<html xmlns="http://www.w3.org/1999/xhtml">	  <head>	  </head>	  <body>		<h2>		  <xsl:value-of select="t:Header/CollectionDetails/Collection"/>		</h2>	  </body>	</html>  </xsl:template></xsl:stylesheet>

Please help Many thanks

Link to comment
Share on other sites

You need to consistently apply that prefix "t" i.e.

<xsl:value-of select="t:Header/t:CollectionDetails/t:Collection"/>

as the xmlns="..." on the root element in the input element applies to that element and all its descendant elements. Also

xmlns="http://www.w3.org/2001/XMLSchema-instance"

on your xsl: stylesheet element does not make sense, you can drop that line.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...