How to ‘select’ from XML with namespaces?

Declare a namespace prefix for the namespace in your XSLT and then select using that prefix:

<xsl:stylesheet ... xmlns:os="urn:schemas-microsoft-com:office:spreadsheet">
  ...   
  <xsl:for-each select="//os:Row">
    ...
  </xsl:for-each>
  ...
</xsl:stylesheet>

This usually results in XPaths that are easy to read. However, XSLT/XPath tools generate the following, equivalent code:

<xsl:for-each select="//*[local-name()='Row' = and namespace-uri()='urn:schemas-microsoft-com:office:spreadsheet']">
   ...
</xsl:for-each>

Leave a Comment