• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 558
  • Last Modified:

XSLT Transformation with namespace

I'm exporting a report from Crystal Reports to XML.  It gives the following data:

<?xml version="1.0" encoding="UTF-8" ?>
<Report xmlns = 'urn:crystal-reports:schemas'>
<OrderItemStates Level="0" Type="Report">
<OrderItemState Level="1" Type="Details">
<OrderId FieldName="{vwReceivingReport.OrderId}">4F548B84-CC34-44E0-8E4A-5AFE436E2D21</OrderId>
<ProductId FieldName="{vwReceivingReport.Item}">INKCOLL_MAT</ProductId>

I'm trying to use the following XSLT on it:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>
<xsl:template match="/">
  <xsl:for-each select="/Report/OrderItemStates/OrderItemState">
      <OrderId><xsl:value-of select="OrderId"/></OrderId>
      <ProductId><xsl:value-of select="ProductId"/></ProductId>
      <State><xsl:value-of select="State"/></State>

The problem is, the line <Report xmlns = 'urn:crystal-reports:schemas'> seems to be causing problems.  When I leave it in, nothing appears from the for-each in the resulting transformation (no OrderItem).  When I manually change it to <Report>, the OrderItems appear as they should.  Any ideas why?  I'm using VB / DomDocument50 to parse this.
1 Solution
Carl TawnSystems and Integration DeveloperCommented:
You need to specify an alias for the namespace and then prefix your node matches with that prefix.

Something like:

    <xsl:stylesheet version="1.0" xmlns:x="urn:crystal-reports:schemas">

        <xsl:template match="/">
            <xsl:for-each select="/x:Report/x:OrderItemStates/x:OrderItemState">



Note that i've stripped out the other two namespace declarations to save space and stripped out everything but the essential XSL tags.

Hope this helps.
judgekingAuthor Commented:
Excellent, it works, thanks very much!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now