2

I know this is super noob, but I just don't understand why my code is not working. Here is XML snippet:

<root>
  <cookies>
    <lastviewedentityname>Category</lastviewedentityname>
    <lastviewedentityinstanceid>72</lastviewedentityinstanceid>
    <lastviewedentityinstancename>Fall Florals</lastviewedentityinstancename>
    some random text bla bla
  </cookies>
  <QueryString>
    <categoryid>34</categoryid>
  </QueryString>
  <!-- other nodes -->
</root>

Here is the XSL snippet:

<?xml version="1.0" standalone="yes" ?>
<package version="2.1" displayname="Categories" debug="false" includeentityhelper="true">
  <PackageTransform>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ise="urn:ise" exclude-result-prefixes="ise">
        <xsl:output method="html" omit-xml-declaration="yes"/>

            <!-- other code -->

            <xsl:value-of select="/root/cookies/lastviewedentityinstanceid"/>

            <!-- other code -->

    </xsl:stylesheet>
  </PackageTransform>
</package>

The result I'm looking for is

72

But it seems I'm getting empty string or something. Looking at this: http://www.w3schools.com/xsl/xsl_value_of.asp, I'm assuming my code is ok. Also, confirming this, is that this code:

<xsl:value-of select="/root/QueryString/categoryid"/>

Gives me the correct value

34

Then in my trying to find answers, I found this site: http://www.mizar.dk/XPath/Default.aspx and I notice when I try here, it highlights the element, not the value inside of it: http://screencast.com/t/NXuNiCHbEd0T

Here is some more info: The system I'm working on is called Interprise Suite Ecommerce (this is where "ise" comes from). It is their web software which integrates with their ERP software called Interprise Suite. ISE an eCommerce software that was adapted from AspDotNetStoreFront some time ago. I'll try to explain the limited knowledge I have.

The page that is being loaded is a product or category page. This particular file I'm working on provides the layout for the sidebar product navigation menu. The file is called rev.categories.xml.config. THis file contains XSLT code. The original XML data that it is transforming, I don't know where it comes from and I don't have access to it. With Dimitre's help in a previous question, I was able to reproduce the XML data in the web pages so I could understand a bit more. In the output of that, the top level node was

<root>

The file that loads this XML package is called template.ascx. It is a template or "master" file. In ASPDNSF, you can use these things called "tokens" to load things into the page and this token is what is calling rev.categories.xml.config to activate and do its thing. The token looks like this:

(!XmlPackage Name="rev.categories"!)

I'm not sure how the tokens work. My thoughts were that it wasn't relevant because everything else in this file is working except for this one single line of code.

Pardon my lack of knowledge, experience and appropriate language.

Edit: Here is a link to the full code of rev.categories.xml.confg. http://jsfiddle.net/v5cNM/

11
  • There's a reference to a namespace ise in the xsl:stylesheet element- is that namespace referenced anywhere in your source XML?
    – Flynn1179
    Commented Sep 9, 2012 at 23:27
  • @Flynn1179 In the source XML, when I searched, it was only found as a substring of an element name iseguid. But in the document I'm working on (with the XSLT), it is used like so: select="ise:GetMLValue(Description)"
    – abc123
    Commented Sep 9, 2012 at 23:43
  • @sungod000, You are usingf a technology (tool) that you haven't explained to us and that you don't fully understand -- this tool isn't XSLT itself, but probably perormas XSLT transformation(s) on XML document(s). Your question cannot be answered as XSLT question if you haven't told us what this other tool is and how it is related (hou it uses) to XSLT. If you want to learn XSLT I recommend that you start with a separate XSLT stylesheet (in its own file) and a separate XML document (also in its own file) -- this is the simplest case of performing an XSLT transformation. Commented Sep 9, 2012 at 23:54
  • @DimitreNovatchev I hear you Dimitre. I'm trying to give you as much as I can. It is just this one line that seems not to be working. Everything else works. I edited my question to show you what seems to be identical code, works fine.
    – abc123
    Commented Sep 10, 2012 at 1:28
  • @sungod000, This isn't helpful. If you want to have a question, you must present all the information that is necessary for other people to repro the problem. I don't see a stand-alone XSLT transformation and you haven't said how the transformation is performed (what tool performs it). As I already said in other comments, what you call "XSLT snippet" isn't syntactically valid XSLT at all. An xsl:stylesheet element must be the top element of the XML document -- it isn't in what you provided. Commented Sep 10, 2012 at 1:39

1 Answer 1

1

Very few if any (I am not aware of such) XSLT processors support embedded stylesheets.

The correct and universally supported way to apply a transformation on an XML document is to place the XSLT stylesheet in a separate XML document (typically residing in its own file).

<xsl:stylesheet> (or its synonym xsl:transform) must be the top element of the stylesheet.

This transformation (occupying its own file):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
  <xsl:value-of select=
  "/root/cookies/lastviewedentityinstanceid"/>
 </xsl:template>
</xsl:stylesheet>

when applied on the provided XML document:

<root>
  <cookies>
    <lastviewedentityname>Category</lastviewedentityname>
    <lastviewedentityinstanceid>72</lastviewedentityinstanceid>
    <lastviewedentityinstancename>Fall Florals</lastviewedentityinstancename>
    some random text bla bla
  </cookies>
  <!-- other nodes -->
</root>

produces the wanted, correct result:

72
5
  • When I removed <?xml?>, <Package> and <PackageTransform> elements, to make the <xsl:stylesheet> tag the top element, I received errors: screencast.com/t/S9EvbMAtaL6
    – abc123
    Commented Sep 9, 2012 at 23:36
  • I wouldn't do that; that's not just a stylesheet, it's a configuration document that contains a stylesheet inside it, and the client code needs it to be where it is. Dimitre's talking about stylesheets embedded in the source XML, which clearly isn't the case here.
    – Flynn1179
    Commented Sep 9, 2012 at 23:46
  • @Flynn1179 I don't know what to say, other code that works in the exact same way works, but this line doesn't.
    – abc123
    Commented Sep 10, 2012 at 1:29
  • @sungod000 Can you tell us what you're processing this with? Commented Sep 10, 2012 at 4:00
  • @C.M.Sperberg-McQueen Forgive me, I'm not sure what you mean. Its an Asp.Net based eCommerce application, if that helps.
    – abc123
    Commented Sep 10, 2012 at 13:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.