Link to home
Start Free TrialLog in
Avatar of tia_kamakshi
tia_kamakshiFlag for United Arab Emirates

asked on

xslt is producing unwanted output

Hi Experts,

I am working on ASP.net 2.0 application using C#

My xslt is producing unwanted output.

Below is my xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0" >
  <xsl:output indent="yes"/>
  <xsl:template match="Image[@CategoryName='Our Services']">
      <xsl:apply-templates select="." mode="pagination" />
  </xsl:template>
  
  <xsl:template match="Image" mode="pagination">
    <article>
      <xsl:value-of select="PreviewImg"/>
    </article>
  </xsl:template>
</xsl:stylesheet>

Open in new window


and Below is my xml
<?xml version="1.0"?>
<ImagesLibrary publicationId="tcm:0-526-1">  
    <Image tcmID="tcm:526-703372" orderno="1" CategoryName="Our Services" Title="Test 6" Published="false" UpdateDate="8/9/2011 1:55:00 PM" URL="/en/Images/ridesandslides_tcm526-702717.jpg">
      <PreviewImg Orientation="Portrait">/en/Images/aoa_tcm526-702718.png</PreviewImg>
      <LowRImg size="210 KB">/en/Images/mainbookingatour_tcm526-702719.jpg</LowRImg>
      <HighRImg size="366 KB">/en/Images/coast_main_tcm526-702720.jpg</HighRImg>
    </Image>
    <Image tcmID="tcm:526-702723" Title="Test1" CategoryName="Another Services" Published="true" UpdateDate="8/8/2011 1:54:00 PM" URL="/en/Images/ridesandslides_tcm526-702717.jpg">
      <PreviewImg Orientation="Portrait">/en/Images/aoa_tcm526-702718.png</PreviewImg>
      <LowRImg size="210 KB">/en/Images/mainbookingatour_tcm526-702719.jpg</LowRImg>
      <HighRImg size="366 KB">/en/Images/coast_main_tcm526-702720.jpg</HighRImg>
    </Image>
  <Image tcmID="tcm:526-702723" Title="Test1" CategoryName="Our Services" Published="true" UpdateDate="8/8/2011 1:54:00 PM" URL="/en/Images/ridesandslides_tcm526-702717.jpg">
    <PreviewImg Orientation="Portrait">/en/Images/aoa_tcm526-702718.png</PreviewImg>
    <LowRImg size="210 KB">/en/Images/mainbookingatour_tcm526-702719.jpg</LowRImg>
    <HighRImg size="366 KB">/en/Images/coast_main_tcm526-702720.jpg</HighRImg>
  </Image>
  
</ImagesLibrary>

Open in new window


Output coming as follows:
<?xml version="1.0" encoding="utf-8"?>  
    <article>/en/Images/aoa_tcm526-702718.png</article>
    
      /en/Images/aoa_tcm526-702718.png
      /en/Images/mainbookingatour_tcm526-702719.jpg
      /en/Images/coast_main_tcm526-702720.jpg
    
  <article>/en/Images/aoa_tcm526-702718.png</article>
  

Open in new window

   

Expected output
<article>/en/Images/aoa_tcm526-702718.png</article>
  <article>/en/Images/aoa_tcm526-702718.png</article>

Open in new window

       
Why in output it is comming extra content
/en/Images/aoa_tcm526-702718.png
            /en/Images/mainbookingatour_tcm526-702719.jpg
      /en/Images/coast_main_tcm526-702720.jpg

Open in new window


Also, I donot wanted
<?xml version="1.0" encoding="utf-8"?>
on my output

Please suggest
Avatar of zc2
zc2
Flag of United States of America image

XSLT's "default template" processes all other elements which your template did not process. Just add this empty template to ignore them:
  <xsl:template match="Image[@CategoryName!='Our Services']">
  </xsl:template>

Open in new window

Avatar of tia_kamakshi

ASKER

Thanks for your reply

I tried but this does not helped. There was no change in the result output after adding template as below

  <xsl:template match="Image[@CategoryName!='Our Services']">
  </xsl:template>
 
  In my actual requirenment this categoryname has to come from parameter. I have added param in my below xslt.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0" >
  <xsl:output indent="yes"/>
  <xsl:param name="LibraryCategory">Our Services</xsl:param>
  
  <xsl:template match="Image[@CategoryName=$LibraryCategory]">
      <xsl:apply-templates select="." mode="pagination" />
  </xsl:template>
  
  <xsl:template match="Image" mode="pagination">
    <article>
      <xsl:value-of select="PreviewImg"/>
    </article>
  </xsl:template>
  <xsl:template match="Image[@CategoryName!=$LibraryCategory]">
  </xsl:template>
</xsl:stylesheet>

Open in new window


If parameter LibraryCategory value is blank or All then I wanted to bring all results irrespective of CategoryName

My above xslt is now giving error at line
<xsl:template match="Image[@CategoryName=$LibraryCategory]">

error: Variables cannot be used within this expression.

Please help me with xslt
ASKER CERTIFIED SOLUTION
Avatar of zc2
zc2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Many Many Thanks for your help
You're welcome