tia_kamakshi
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
and Below is my xml
Output coming as follows:
Expected output
Why in output it is comming extra content
Also, I donot wanted
<?xml version="1.0" encoding="utf-8"?>
on my output
Please suggest
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>
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>
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>
Expected output
<article>/en/Images/aoa_tcm526-702718.png</article>
<article>/en/Images/aoa_tcm526-702718.png</article>
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
Also, I donot wanted
<?xml version="1.0" encoding="utf-8"?>
on my output
Please suggest
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.
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 =$LibraryC ategory]">
error: Variables cannot be used within this expression.
Please help me with xslt
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
</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>
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
error: Variables cannot be used within this expression.
Please help me with xslt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many Many Thanks for your help
You're welcome
Open in new window