Generating XSLT for the given XML. Error: Mismatch
I Have an XML something like this
<NavigatorItems>
<Navigator Name="Product">
<ModifierName>Product1</ModifierName>
<ModifierLink>www.Product1.com</ModifierLink>
<ModifierName>Product2</ModifierName>
<ModifierLink>www.Product2.com</ModifierLink>
<ShowAll>www.ProductMain.com</ShowAll>
</Navigator>
<Na开发者_Go百科vigator Name="Article">
<ModifierName>Article1</ModifierName>
<ModifierLink>www.Article1.com</ModifierLink>
<ModifierName>Article2</ModifierName>
<ModifierLink>www.Article2.com</ModifierLink>
<ShowAll>www.ArticleMain.com</ShowAll>
</Navigator>
</NavigatorItems>
I Need to show something like this:
I tried the following XSLT but it throws some error (mismatch):
XML Parsing Error: mismatched tag. Expected: </ModifierName>
My Code:
<xsl:for-each select="NavigatorItems/Navigator">
<xsl:variable name="link" select="ModifierLink"/>
<tr>
<td><a href ="{$link}"><xsl:value-of select="ModifierName"/></td>
</tr>
<xsl:test select="ShowAll">
<xsl:variable name="linkShowAll" select="ShowAll"/>
<tr> <td> <a href="{$linkShowAll}"> View More Results <td> </tr>
</xsl:test>
</xsl:for-each>
Where Am I going wrong ? Please Suggest...
There were a number of problems with your code. I think I've fixed them all, but let me know if you have any problems with this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xsl:for-each select="NavigatorItems/Navigator">
<xsl:variable name="link" select="ModifierLink"/>
<tr>
<td>
<a><xsl:attribute name="href"><xsl:value-of select="ModifierLink"/></xsl:attribute><xsl:value-of select="ModifierName" /></a>
</td>
</tr>
<xsl:if test select="ShowAll != ''">
<tr>
<td>
<a><xsl:attribute name="href"><xsl:value-of select="ShowAll"/>View More Results</a>
</td>
</tr>
</xsl:test>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
精彩评论