Result of XSLT function appears in preview, but not in output?

Topics: XSLT
May 27, 2011 at 12:33 PM

Hi,

I've made an XSLT function that returns an image from the media archive which is a "No image available" placeholder image. The XSLT function is very simple and looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0" xmlns:lang="http://www.composite.net/ns/localization/1.0" xmlns:f="http://www.composite.net/ns/function/1.0" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xsl in lang f">
  <xsl:template match="/">
    <imagePath>
      <xsl:value-of select="/in:inputs/in:result[@name='GetIImageFileXml']/IImageFile/@KeyPath"/>
    </imagePath>
  </xsl:template>
</xsl:stylesheet>
I've selected XML as the result type. On the Function Calls tab, I've set the following up:

<f:functions xmlns:f="http://www.composite.net/ns/function/1.0">
  <f:function name="Composite.Data.Types.IImageFile.GetIImageFileXml" localname="GetIImageFileXml">
    <f:param name="PropertyNames">
      <f:paramelement value="KeyPath" />
    </f:param>
    <f:param name="Filter">
      <f:function name="Composite.Data.Types.IImageFile.FieldPredicatesFilter">
        <f:param name="Title">
          <f:function name="Composite.Utils.Predicates.StringEquals">
            <f:param name="Value" value="Intet billede" />
          </f:function>
        </f:param>
      </f:function>
    </f:param>
  </f:function>
</f:functions>
It basically looks for an image with a title of "Intet billede" (Which translates to "No image").

In the preview of this function, the input looks like this:

<in:inputs xmlns:in="http://www.composite.net/ns/transformation/input/1.0">
    <!-- Function Call Result (0 ms), XPath /in:inputs/in:result[@name='GetIImageFileXml']/IImageFile -->
    <in:result name="GetIImageFileXml">
        <IImageFile KeyPath="MediaArchive:b35e799a-6c07-48e7-9541-e96ee3e1900d" xmlns=""/>
    </in:result>
</in:inputs>

And the output looks like this:

<imagePath xmlns="http://www.w3.org/1999/xhtml">MediaArchive:b35e799a-6c07-48e7-9541-e96ee3e1900d</imagePath>

That's great! It works!

But, now I'm trying to use this function in another XSLT function, and I simply can't get to the value. I've created a test XSLT function just to get it to work, but without luck. So now I hope there's someone here who can tell me what I'm doing wrong.

The XSLT function is calling my function in the Function Calls tab, like this:

<f:functions xmlns:f="http://www.composite.net/ns/function/1.0">
  <f:function name="General.GetMissingImage" localname="GetMissingImage" />
</f:functions>

And on the Preview tab, in the Input window, the result is this:

<in:inputs xmlns:in="http://www.composite.net/ns/transformation/input/1.0">
    <!-- Function Call Result (0 ms), XPath /in:inputs/in:result[@name='GetMissingImage']/imagePath -->
    <in:result name="GetMissingImage">
        <imagePath xmlns="http://www.w3.org/1999/xhtml">MediaArchive:b35e799a-6c07-48e7-9541-e96ee3e1900d</imagePath>
    </in:result>
</in:inputs>

Cool, my function works, and the image path is right there! Let's get it with XPath!

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0" xmlns:lang="http://www.composite.net/ns/localization/1.0" xmlns:f="http://www.composite.net/ns/function/1.0" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xsl in lang f">
  <xsl:template match="/">
    <html>
      <head></head>
      <body>
        <xsl:value-of select="/in:inputs/in:result[@name='GetMissingImage']/imagePath" />
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

And this is where it blacks out for me. When I look in the Output window on the Preview tab, the result is this:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head/>
    <body/>
</html>

Nothing!? How can that be? I've been trying so many things, that I've lost track of them. I was hoping someone could help me pinpoint what I'm doing wrong here. Is it my XPath expression? I copied it from the Input window, so I guess it should be correct!? I've tried returning the image path as an attribute on the "image" element instead, but I still can't get to it. I've even tried the XPath expression "/in:inputs/in:result//image" but that still doesn't return anything.

I'm really lost here, does anyone have a suggestion what to try next?

Coordinator
May 27, 2011 at 1:15 PM

Hello,

Edit you first XSLT and add namespase xmlns="" like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0" xmlns:lang="http://www.composite.net/ns/localization/1.0" xmlns:f="http://www.composite.net/ns/function/1.0" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xsl in lang f">
  <xsl:template match="/">
    <imagePath xmlns="">
      <xsl:value-of select="/in:inputs/in:result[@name='GetIImageFileXml']/IImageFile/@KeyPath"/>
    </imagePath>
  </xsl:template>
</xsl:stylesheet>

and then check out your example.

Coordinator
May 27, 2011 at 1:16 PM

Most likely that XPath expression

/in:inputs/in:result[@name='GetMissingImage']/imagePath

is selecting  "imagePath" elements that belong to an empty xml namespace.

Try following:

1) add namespace

   xmlns:x="http://www.w3.org/1999/xhtml"

2) change XPath to

/in:inputs/in:result[@name='GetMissingImage']/x:imagePath
May 27, 2011 at 1:38 PM

You're both right! It was an issue with the namespace. I tried your suggestion, Inna, and that resolved the issue.

Thank you so much, both of you!