Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 7th, 2008, 06:27 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I posted a complete working stylesheet. Does that not work for you?
As for the snippet you have provided, I don't see how that could "screw up" or "bomb out" the result but those terms do not tell us anyway what exactly happens.
Please provide a minimal and complete stylesheet and show us the result you get and explain in what way exactly it is screwed up.
If the stylesheet transformation does not run at all ("bomb out") then show us the .NET code you use to run the transformtion.

--
  Martin Honnen
  Microsoft MVP - XML
 
Old May 7th, 2008, 09:12 AM
Registered User
 
Join Date: May 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Clark Kent
Default

Sorry guys, I didnt even bother to check whether my code was failing and that is the case. Here is my .Net code:

XPathDocument myXPathDocument = new XPathDocument("C:\\xmlSource.xml");
                XslTransform myXslTransform = new XslTransform();
                XmlTextWriter writer = new XmlTextWriter("C:\\transformed.xml", null);
                myXslTransform.Load("C:\\NewTransform.xslt");
                myXslTransform.Transform(myXPathDocument, null, writer);
                writer.Close();
                StreamReader stream = new StreamReader("C:\\transformed.xml");
                Console.Write(stream.ReadToEnd());

I'm getting the following error during myXslTransform.Transform().

"Cannot find the script or external object that implements prefix 'exsl'."


Here is the top of my stylesheet(I downloaded the str.xsl and corresponding files so the import is OK):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:str="http://exslt.org/strings"
                xmlns:exsl="http://exslt.org/common"
                extension-element-prefixes="str exsl">

  <xsl:import href="str.xsl" />

Here is the chunk of the transform I'm trying to parse through the "Market" element in the original example I posted above:

<xsl:variable name="tokens">
         <xsl:call-template name="str:_tokenize-delimiters">
          <xsl:with-param name="string" select="Market"></xsl:with-param>
          <xsl:with-param name="delimiters" select="'|'"></xsl:with-param>
        </xsl:call-template>
      </xsl:variable>

        <xsl:for-each select="exsl:node-set($tokens)/token">
          <Market>
            <xsl:value-of select="."/>
          </Market>
        </xsl:for-each>


Also, I've got all three of the str templates referenced at the bottom of my stylesheet.

Does this help? I really appreciate the help from you guys!

 
Old May 7th, 2008, 09:52 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Are you still using .NET 1.x? Otherwise you should not use the obsolete XslTransform but rather XslCompiledTransform instead. With that my stylesheet works.
If you want to continue to use XslTransform then you can't use exsl:node-set as it does not support that. Instead you need to use a different namespace:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:str="http://exslt.org/strings"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  version="1.0"
  exclude-result-prefixes="str msxsl">

  <xsl:include href="http://www.exslt.org/str/functions/tokenize/str.tokenize.template.xsl"/>

  <xsl:output method="xml" indent="yes"/>

  <xsl:strip-space elements="*"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="market">
    <xsl:copy>
      <xsl:variable name="tokens">
        <xsl:call-template name="str:tokenize">
          <xsl:with-param name="string" select="."/>
          <xsl:with-param name="delimiters" select="'|'"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:for-each select="msxsl:node-set($tokens)/token">
        <m>
          <xsl:value-of select="."/>
        </m>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
--
  Martin Honnen
  Microsoft MVP - XML
 
Old May 7th, 2008, 09:54 AM
Registered User
 
Join Date: May 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Clark Kent
Default

It appears the problem is definitely with the for-each loop. If I just us the tokens variable and spit that to the resulting XML, I get the original input with the delimiters removed.

 
Old May 7th, 2008, 09:55 AM
Registered User
 
Join Date: May 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Clark Kent
Default

OK, I'll give the CompiledTransform a shot.

 
Old May 7th, 2008, 10:10 AM
Registered User
 
Join Date: May 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Clark Kent
Default

SWEET! It's working! Just had to change a few things around in the .Net code. Thank you both for the help so much - sorry for being a pain in the butt.
:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating a comma-delimited data in XSLT dude153 XSLT 2 November 30th, 2007 12:12 PM
Write XML element into textbox with XSLT tcstom XSLT 4 July 5th, 2006 04:08 AM
xml element values vakorde XSLT 3 May 2nd, 2006 04:36 AM
Converting XML to XML (making element mandatory) boondocksaint20 XSLT 8 April 28th, 2006 10:54 AM
Update a table with XML element values alavastros XML 1 July 16th, 2004 11:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.