|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Trouble with something that seems so simple.
Please, could anyone explain to my brickheaded self what i'm doing wrong? Yes, i'm a newbie to xml. Heres my XML file:
<Results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xyz"> - <KeywordsRatingSet keywords="superbikes"> <Market>us</Market> </KeywordsRatingSet> - <ResultSet id="relatedSearchResults" numResults="20"> - <Category type="related"> <Search num="1">Superbike</Search> <Search num="2">Used bike</Search> <Search num="3">Sport bike</Search> <Search num="4">Used dirt bike</Search> <Search num="5">Dirt bike accessory</Search> <Search num="6">Motor bike</Search> <Search num="7">Dirt bike gear</Search> <Search num="8">Performance bicycle</Search> <Search num="9">Sportbikes</Search> <Search num="10">World superbike</Search> <Search num="11">Electric bicycle</Search> <Search num="12">Bike race</Search> <Search num="13">Used dirt bike for sale</Search> <Search num="14">Sport bike part</Search> <Search num="15">Sport bike picture</Search> <Search num="16">Sport bike video</Search> <Search num="17">Yamaha dirt bike</Search> <Search num="18">Honda dirt bike</Search> <Search num="19">Dirt bike part</Search> <Search num="20">Sport bike accessory</Search> </Category> </ResultSet> </Results> And my XSLT file follows: <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl utput method="html" /><xsl:template match="/"> <xsl:apply-templates select="Results/ResultSet" /> </xsl:template> <xsl:template match="Category"> <xsl:value-of select="Search" /> </xsl:template> </xsl:stylesheet> I never seem to get anything returned. I figure ive got my XSLT formatted incorrectly. Anyone straighten me out? ![]() |
|
#2
|
||||
|
||||
|
OK, so you are not cycling through the "search" -tags. Maybe this is what you are after:
Code:
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" /> <xsl:template match="/"> <xsl:apply-templates select="Results/ResultSet" /> </xsl:template> <xsl:template match="Category"> <xsl:for-each select="Search"> <xsl:value-of select="node()" /><br/> </xsl:for-each> </xsl:template> </xsl:stylesheet> |
|
#3
|
|||
|
|||
|
One way is as follows:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<xsl:apply-templates select="/Results/ResultSet" />
</xsl:template>
<xsl:template match="/Results/ResultSet">
<xsl:value-of select="Category" />
</xsl:template>
</xsl:stylesheet>
Another (and better) way is: Code:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<xsl:apply-templates select="/Results/ResultSet" />
</xsl:template>
<xsl:template match="/Results/ResultSet">
<xsl:for-each select="Category/Search">
<xsl:value-of select="." />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
|
|
#4
|
|||
|
|||
|
Closer to a solution...
Thanks for the assistance guys, but I realized last nite that my problem was not with my XSLT stylesheet. There is a namespace involved with the original XML file, and upon removal of that namespace, all of my transforms work. Im gonna post a separate thread addressing this problem.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Trouble with something that seems so simple. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|