вторник, август 31, 2010

XSLT match elements with namespace (XPath)

Example XML file where all elements have (default) namespace:
<rootnode xmlns="http://www.mydomain.com/2010">
  <title>title of element 1</title>
  <title>title of element 2</title>
Example XSL file matching elements from the XML file above:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
 <xsl:template match="/">
  <xsl:for-each select="customNS:rootnode/customNS:myelement">
   <entrytitle><xsl:value-of select="customNS:title"/></entrytitle>
   <entryurl><xsl:value-of select="customNS:uri"/></entryurl>
The namespace from the XML file should be declared in the XSL file and should be given a name (e.g. customNS), so its elements can be referenced from the XSL file.

Няма коментари: