?
Solved

XSLT Transformation with namespace

Posted on 2005-03-02
2
Medium Priority
?
492 Views
Last Modified: 2013-11-19
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>
<State>RECEIVED</State>
</OrderItemState>
</OrderItemStates>
</Report>

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="/">
<OrderStateNotification>
  <OrderItems>
  <xsl:for-each select="/Report/OrderItemStates/OrderItemState">
    <OrderItem>
      <OrderId><xsl:value-of select="OrderId"/></OrderId>
      <ProductId><xsl:value-of select="ProductId"/></ProductId>
      <State><xsl:value-of select="State"/></State>
    </OrderItem>
  </xsl:for-each>
  </OrderItems>
</OrderStateNotification>
</xsl:template>
</xsl:stylesheet>

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.
0
Comment
Question by:judgeking
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 200 total points
ID: 13440575
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">
            </xsl:for-each>

        </xsl:template>

    </xsl:stylesheet>


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.
       
0
 
LVL 6

Author Comment

by:judgeking
ID: 13454023
Excellent, it works, thanks very much!

-J
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question