tia_kamakshi
asked on
Duplicating main node
Hi Experts,
I am working on ASP.net 2.0 using C#
My xslt is producing root node (<articles>) again and again with each match result
Please find my xslt, xml, output below
XSLT:
XML:
OUTPUT
EXPECTED OUTPUT
Also, I donot wanted
<?xml version="1.0" encoding="utf-8"?>
in my output
Please help me fixing the issue
Thanks
I am working on ASP.net 2.0 using C#
My xslt is producing root node (<articles>) again and again with each match result
Please find my xslt, xml, output 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">
<articles>
<xsl:if test="@CategoryName=$LibraryCategory">
<xsl:apply-templates select="." mode="pagination" />
</xsl:if>
</articles>
</xsl:template>
<xsl:template match="Image" mode="pagination">
<article>
<a href="/english/media/media-library/images/image01.aspx" data-lightbox="/english/media/media-library/images/image01.aspx?html=fragment">
<img src="/images/media/image_thumbnail01.jpg" alt="" >
<xsl:attribute name="src">
<xsl:value-of select="PreviewImg"/>
</xsl:attribute>
</img>
</a>
</article>
</xsl:template>
</xsl:stylesheet>
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
<?xml version="1.0" encoding="utf-8"?>
<articles><article><a href="/english/media/media-library/images/image01.aspx" data-lightbox="/english/media/media-library/images/image01.aspx?html=fragment"><img alt="" src="/en/Images/aoa_tcm526-702718.png" /></a></article></articles>
<articles />
<articles><article><a href="/english/media/media-library/images/image01.aspx" data-lightbox="/english/media/media-library/images/image01.aspx?html=fragment"><img alt="" src="/en/Images/aoa_tcm526-702718.png" /></a></article></articles>
EXPECTED OUTPUT
<?xml version="1.0" encoding="utf-8"?>
<articles>
<article>
<a href="/english/media/media-library/images/image01.aspx" data-lightbox="/english/media/media-library/images/image01.aspx?html=fragment">
<img alt="" src="/en/Images/aoa_tcm526-702718.png" />
</a>
</article>
<article>
<a href="/english/media/media-library/images/image01.aspx" data-lightbox="/english/media/media-library/images/image01.aspx?html=fragment">
<img alt="" src="/en/Images/aoa_tcm526-702718.png" />
</a>
</article>
</articles>
Also, I donot wanted
<?xml version="1.0" encoding="utf-8"?>
in my output
Please help me fixing the issue
Thanks
this way you create the articles node one level higher
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
but your full xslt looks nicer like this (no duplicate processing but precise selection
<?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="ImagesLibrary">
<articles>
<xsl:apply-templates select="Image[@CategoryName=$LibraryCategory]"/>
</articles>
</xsl:template>
<xsl:template match="Image">
<article>
<a href="/english/media/media-library/images/image01.aspx" data-lightbox="/english/media/media-library/images/image01.aspx?html=fragment">
<img src="/images/media/image_thumbnail01.jpg" alt="" >
<xsl:attribute name="src">
<xsl:value-of select="PreviewImg"/>
</xsl:attribute>
</img>
</a>
</article>
</xsl:template>
</xsl:stylesheet>
changing the output line in the xslt to omit the declaration will get rid of teh declaration
<xsl:output indent="yes" omit-xml-declaration="yes" />
but I assume your C# will ignore the serialisation settings.
If the above does not work, please show us the transforming C#
<xsl:output indent="yes" omit-xml-declaration="yes"
but I assume your C# will ignore the serialisation settings.
If the above does not work, please show us the transforming C#
ASKER
Many Thanks for your replies
Can I remove the line below from my output
<?xml version="1.0" encoding="utf-8"?>
Also, can I add condition here saying if
value of parameter is 'All' or '' then give results from all image nodes
somethhing like
<xsl:apply-templates select="Image"/>
if parameter LibraryCategory has the value other than 'All' or ''
then give results from
<xsl:apply-templates select="Image[@CategoryNam e=$Library Category]" />
Thanks again
Can I remove the line below from my output
<?xml version="1.0" encoding="utf-8"?>
Also, can I add condition here saying if
value of parameter is 'All' or '' then give results from all image nodes
somethhing like
<xsl:apply-templates select="Image"/>
if parameter LibraryCategory has the value other than 'All' or ''
then give results from
<xsl:apply-templates select="Image[@CategoryNam
Thanks again
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
welcome
Open in new window
should be
Open in new window