views:

74

answers:

3

I have been using a CMS which is called Umbraco(umbraco.org) and for displaying flash news on the website using SlideShowPro Standalone product(www.slideshowpro.net)

In brief I created a section on admin panel as follows.

-Flash(which has a xslt file)
- Month name
- A node with image
- A node with video

Every month I will be creating a node with name of the month and add image and videos to them. Month node might have all image or video perhaps both are mixed. I do not have any input xml file cause on SlideShowPro Standalone has only a file which outputs desired xml file for flash

here is the xml file:

<album id="ssp" lgPath="" tnPath="" title="Album One" description="" tn="">
    <img src="1.jpg" id="id1" title="" caption="" link="" target="_blank" pause="" />
    <img src="1.f4v" id="id1" tn="" title="" caption="" link="" target="_blank" pause="" vidpreview" />
</album>

What I did in xslt file is;

<xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
            <album lgPath="http://localhost" tnPath="http://localhost" title="{data[@alias = 'albumTitle']}" description="{data[@alias = 'albumDescription']}" tn="http://localhost"&gt;
                <xsl:for-each select="node">
                    <xsl:if test = "string-length(./data [@alias = 'image']) &gt; 0" >                                                  
                                                <img src="{data[@alias = 'image']}" title="{data[@alias = 'title']}" caption="{data[@alias = 'caption']}" link="{data[@alias = 'link']}" target="_blank" pause=""/>                                                         
                    </xsl:if>       
                    <xsl:if test = "string-length(./data [@alias = 'video']) &gt; 0" >                                                  
                                                <img src="{data[@alias = 'video']}" tn="http://localhost" title="{data[@alias = 'title']}" caption="{data[@alias = 'caption']}" link="{data[@alias = 'link']}" target="_blank" pause="" vidpreview="/flash/gallery/album2/video/1_preview.png"/>                                                        
                    </xsl:if>

                </xsl:for-each>     
                        </album>
        </xsl:for-each>

and that outputs

<album lgPath="http://localhost" tnPath="http://localhost" title="" description="" tn="http://localhost"&gt;&lt;img src="/media/951/untitled.png" title="örnek" caption="örnek" link="" target="_blank" pause=""/><img src="/media/1026/1.f4v" title="flash" caption="flash" link="" target="_blank" pause=""/></album>

Even though Larsh pointed out that I should use statament, the result is same...

+1  A: 

I'm unsure what your source data is like, but assuming that it doesn't have nested <node> elements, the problem is that the second xsl:for-each should be

<xsl:for-each select=".">

because the context item inside the first for-each will be the <node> element, therefore the instruction you posted would be seeking a further child element.

Nick Jones
OK. It looks like this isn't the issue, could you post some sample source data.
Nick Jones
by meaning source data you mean whole xslt file?
deniz_seaside
No, I mean that input xml file which you are applying the xslt to.
Nick Jones
Sorry, I can't seen the input xml in your comment - can you post it in a code block in the question
Nick Jones
I really need to be able to see the input to be able to be able to work out what is going wrong. Can you replace your stylesheet with an <xsl:copy-of select="."/> which should hopefully should copy your input to the output.
Nick Jones
A: 

Nasılsınız?!

Deniz, it would still be good to see your input XML. It looks like what you posted in your comment was a bit of the desired output XML. The best way to post it is to edit your original question and put the input XML there, at least a sample.

In the meantime, I'm wondering, is it possible for a <node> element to have both a

<data alias="image">

child and a

<data alias="video">

child? If so, that would explain why in those cases you're not getting the <img src="{data[@alias = 'video']}"> output.

The <xsl:choose> instruction will only "execute" one of the <xsl:when> instructions each time the <xsl:choose> is processed (in this case, once for every iteration of the <xsl:for-each> loop). So if there is a `data[@aliasIf you need to be able to handle both an image data child and a video data child, use

<xsl:if test=...>

for each of them, instead of

<xsl:choose>
  <xsl:when test=...>

If that doesn't address the problem, please do post a sample of your input XML, and format it using the 'code' formatting button (with the 101 010 icon).

LarsH
larsh, thanks for the info. I will be updating my question soon...
deniz_seaside
my original question has been updated larsh, hth...
deniz_seaside
A: 

UPDATE: @deniz_seaside, please give us the XML document and also see it for the first time.

Then, probably, you'll write your transformation again, this time much better.

Here is how to obtain the XML document that you don't have: just apply this transformation to this unknown document:

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

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

Or even shorter:

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

 <xsl:template match="/">
  <xsl:copy-of select="."/>
 </xsl:template>
</xsl:stylesheet>

<xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']"> 
            <album lgPath="http://localhost" tnPath="http://localhost" title="{data[@alias = 'albumTitle']}" description="{data[@alias = 'albumDescription']}" tn="http://localhost"&gt; 
                <xsl:for-each select="node"> 

The second <xsl:for-each> is most likely incorrect. It will select for processing all nodes named node of the current node, which is also named node. Usually a node named node doesn't have children named node, too.

The solution is to remove the second <xsl:for-each> instruction and leave its content ( body) in the body of the first <xsl:for-each> instruction.

Do note:

  1. As you haven't provided any source XML document, your problem is most likely duew to the bad weather.

  2. Never use the name node for an element, attribute or processing-instruction. You are increasing the chances of getting confused and committing errors by a factor of 1000.

Dimitre Novatchev
Dimitre thanks for the valuable infos. I supplied all the infos I could find but I would take into consedaration your suggestion as well. I am also not good at xslt and try to gain knowledge for it.
deniz_seaside