XSLT - HTML Transform problems

I am having problems with this xslt transformation

The XSLT should make it obivous what i am trying to achieve

I have included a cut down version of the XML, and my XSLT attempt, i keep getting the error invalid pattern in XMLSpy

Thank you for looking at this
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="file:///C:/Documents%20and%20Settings/Chris/My%20Documents/Altova/XMLSpy2009/Examples/ClosestSoFar.xslt"?>
<ProductSearch xmlns="urn:yahoo:prods">
	<Categories total_subcategories="18">
		<SubCategory>
			<Title>Projector Accessories</Title>
			<Value>100375223</Value>
			<NumberOfProducts>1</NumberOfProducts>
		</SubCategory>
	</Categories>
	<Products firstResultPosition="1" totalResultsAvailable="435" totalResultsReturned="20">
		<Product type="Offer">
			<Offer id="960e67b21e0ddfafdbb0b77716e98bbc">
				<Url>http://uk.shopping.yahooapis.com/ctl/go/sitesearchGo?.ts=1246725457647&amp;.sig=h4eRVQJiZWr.Ld1JJdxhNvz_ECc-&amp;offerId=960e67b21e0ddfafdbb0b77716e98bbc&amp;searchId=87248117220_1246725457645_1206933&amp;affiliationId=96929528&amp;country=uk&amp;wait=true&amp;comId=7546223&amp;catId=127101</Url>
				<CompareUrl>http://audiovisual.kelkoo.co.uk/p-plasma-tvs-127101/samsung-ps50b430-19601770?partnerId=96929528</CompareUrl>
				<ProductName>Samsung PS50B430 ** Special Deal ** Available if...</ProductName>
				<Price currency="gbp">699.00</Price>
				<DeliveryCost>0.0</DeliveryCost>
				<DeliveryTime>1 To 3 Working Days</DeliveryTime>
				<Availability>Availability: In stock</Availability>
				<Used>false</Used>
				<ListImage>
					<Url>http://img.kelkoo.com/uk/medium/624/631/87817543067979507255394251041155631624.jpg</Url>
					<Height>90</Height>
					<Width>90</Width>
				</ListImage>
				<GridImage>
					<Url>http://img.kelkoo.com/uk/medium/624/631/87817543067979507255394251041155631624.jpg</Url>
					<Height>90</Height>
					<Width>90</Width>
				</GridImage>
				<Summary>Free Mainland UK Delivery Only - Samsung PS50B430 50&amp;quot; HD Ready PLASMA Picture Playback Screen Size 50 &amp;quot;&amp;quot; Resolution max. 1365 x 768 1365 x 768 Image ...</Summary>
				<Merchant id="7546223">
					<Name>Electro Centre</Name>
				</Merchant>
				<CatalogID>127101-19601770</CatalogID>
				<Category id="127101">
					<Name>Plasma TVs</Name>
				</Category>
			</Offer>
		</Product>
	</Products>
	<Warnings>
		<Warning>The "merchantId" parameter is not given. The default value "-1" is used.</Warning>
		<Warning>The "logicalType" parameter is not given. The default value "and" is used.</Warning>
	</Warnings>
</ProductSearch>
 
 
<?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" xmlns:user="urn:comparionsplus-com:xslt">
	<xsl:output method="html"/>
	<xsl:template match="ProductSearch/Products">
		<xsl:variable name="resultsPosition">
			<xsl:value-of select="@firstResultPosition"/>
		</xsl:variable>
		<xsl:variable name="totalResults">
			<xsl:value-of select="@totalResultsAvailable"/>
		</xsl:variable>
		<xsl:variable name="returnedResults">
			<xsl:value-of select="@totalResultsReturned"/>
		</xsl:variable>
	</xsl:template>
	<xsl:template match="Products/Product/Offer/">
		<xsl:variable name="prodName">
			<xsl:value-of select="ProductName"/>
		</xsl:variable>
		<xsl:variable name="prodDesc">
			<xsl:value-of select="Summary"/>
		</xsl:variable>
		<xsl:variable name="catID">
			<xsl:value-of select="Category"/>
		</xsl:variable>
		<xsl:variable name="catName">
			<xsl:value-of select="Category/Name"/>
		</xsl:variable>
		<xsl:variable name="merchantID">
			<xsl:value-of select="Merchant/@id"/>
		</xsl:variable>
		<xsl:variable name="merchantName">
			<xsl:value-of select="Merchant/Name"/>
		</xsl:variable>
		<xsl:variable name="clickLink">
			<xsl:value-of select="Url"/>
		</xsl:variable>
		<xsl:variable name="imageLink">
			<xsl:value-of select="ListImage/Url"/>
		</xsl:variable>
		<xsl:variable name="compareLink">
			<xsl:value-of select="CompareUrl"/>
		</xsl:variable>
		<xsl:variable name="prodPrice">
			<xsl:value-of select="Price"/>
		</xsl:variable>
		<xsl:variable name="delCost">
			<xsl:value-of select="DeliveryCost"/>
		</xsl:variable>
		<xsl:variable name="compareLink">
			<xsl:value-of select="CompareUrl"/>
		</xsl:variable>
		<xsl:variable name="prodAvail">
			<xsl:value-of select="Availability"/>
		</xsl:variable>
		<xsl:variable name="prodState">
			<xsl:value-of select="Used"/>
		</xsl:variable>
	</xsl:template>
	<xsl:apply-templates/>
					
					First Result Position: <xsl:value-of select="$resultsPosition"/>
	<br/>
					Total Results: <xsl:value-of select="$totalResults"/>
	<br/>
					Results on Page: <xsl:value-of select="$returnedResults"/>
	<br/>
					
					Category id: <xsl:value-of select="$catID"/>
	<br/>
					Product Name: <xsl:value-of select="$prodName"/>
	<br/>
					Long Desc: <xsl:value-of select="$prodDesc"/>
	<br/>
					Category Name: <xsl:value-of select="$catName"/>
	<br/>
					Merchant ID: <xsl:value-of select="$merchantID"/>
	<br/>
					Merchant Name: <xsl:value-of select="$merchantName"/>
	<br/>
					Product Link: <xsl:value-of select="$clickLink"/>
	<br/>
					Image Link: <xsl:value-of select="$imageLink"/>
	<br/>
					Comparison Link: <xsl:value-of select="$compareLink"/>
	<br/>
					Product Price: <xsl:value-of select="$prodPrice"/>
	<br/>
					Delivery Price: <xsl:value-of select="$delCost"/>
	<br/>
					New/Used: <xsl:value-of select="$prodState"/>
	<br/>
					Availabile: <xsl:value-of select="$prodAvail"/>
	<br/>
					Short Desc: <xsl:value-of select="substring(substring-before($prodDesc,'.'),1,1000)"/>
	<br/>
	<xsl:template match="Warnings"/>
	<xsl:template match="Categories/*"/>
	<xsl:template match="Products/Product/Offer/GridImage"/>
</xsl:stylesheet>

Open in new window

LVL 3
QuinnDesterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
No, the XSLT does not make it entirely obvious what you are trying to achiev.
You have one obvious error
line 59 of the XSLT, you have     <xsl:apply-templates/>
and that apply templates and all the following lines are not in a template.
These actions are only allowed inside an xsl:template
0
Geert BormansInformation ArchitectCommented:
further more

line 15
   <xsl:template match="Products/Product/Offer/">
is a pattern that is not allowed,
it should be
   <xsl:template match="Products/Product/Offer">

line 49
        <xsl:variable name="compareLink">
is allready defined
0
Geert BormansInformation ArchitectCommented:
I assume th eproblem is the line 15 one,
all the others are likely due to your cutting in the XSLT for posting

A good tip, make sure that when posting snippets, that you isolate the problem,
not introducing errors because of the cut
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

QuinnDesterAuthor Commented:
Thanks Gertone

I have corrected the Line 15 error and removed the <xsl:apply-templates/>
the line 49 error was introduced through the cut and past sorry about that i will be more carful in future.

I know get the error that the parameter or veriable is already defined on line 57 this should be where the XSLT starts to outbut the results.

the xslt here is just trying to output the information into a list (done this way so i can get the XSLT functioning before applying any HTML formating to the results)

I am completely new to XSLT this is my first attempt at doing anything with it, Please bare in mind that what you see as obvious may be completely oblivious to me.

Thanks
<?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" xmlns:user="urn:comparionsplus-com:xslt">
	<xsl:output method="html"/>
	<xsl:template match="ProductSearch/Products">
		<xsl:variable name="resultsPosition">
			<xsl:value-of select="@firstResultPosition"/>
		</xsl:variable>
		<xsl:variable name="totalResults">
			<xsl:value-of select="@totalResultsAvailable"/>
		</xsl:variable>
		<xsl:variable name="returnedResults">
			<xsl:value-of select="@totalResultsReturned"/>
		</xsl:variable>
	</xsl:template>
	<xsl:template match="Products/Product/Offer">
		<xsl:variable name="prodName">
			<xsl:value-of select="ProductName"/>
		</xsl:variable>
		<xsl:variable name="prodDesc">
			<xsl:value-of select="Summary"/>
		</xsl:variable>
		<xsl:variable name="catID">
			<xsl:value-of select="Category"/>
		</xsl:variable>
		<xsl:variable name="catName">
			<xsl:value-of select="Category/Name"/>
		</xsl:variable>
		<xsl:variable name="merchantID">
			<xsl:value-of select="Merchant/@id"/>
		</xsl:variable>
		<xsl:variable name="merchantName">
			<xsl:value-of select="Merchant/Name"/>
		</xsl:variable>
		<xsl:variable name="clickLink">
			<xsl:value-of select="Url"/>
		</xsl:variable>
		<xsl:variable name="imageLink">
			<xsl:value-of select="ListImage/Url"/>
		</xsl:variable>
		<xsl:variable name="compareLink">
			<xsl:value-of select="CompareUrl"/>
		</xsl:variable>
		<xsl:variable name="prodPrice">
			<xsl:value-of select="Price"/>
		</xsl:variable>
		<xsl:variable name="delCost">
			<xsl:value-of select="DeliveryCost"/>
		</xsl:variable>
		<xsl:variable name="prodAvail">
			<xsl:value-of select="Availability"/>
		</xsl:variable>
		<xsl:variable name="prodState">
			<xsl:value-of select="Used"/>
		</xsl:variable>
	</xsl:template>
					
					First Result Position: <xsl:value-of select="$resultsPosition"/>
	<br/>
					Total Results: <xsl:value-of select="$totalResults"/>
	<br/>
					Results on Page: <xsl:value-of select="$returnedResults"/>
	<br/>
					
					Category id: <xsl:value-of select="$catID"/>
	<br/>
					Product Name: <xsl:value-of select="$prodName"/>
	<br/>
					Long Desc: <xsl:value-of select="$prodDesc"/>
	<br/>
					Category Name: <xsl:value-of select="$catName"/>
	<br/>
					Merchant ID: <xsl:value-of select="$merchantID"/>
	<br/>
					Merchant Name: <xsl:value-of select="$merchantName"/>
	<br/>
					Product Link: <xsl:value-of select="$clickLink"/>
	<br/>
					Image Link: <xsl:value-of select="$imageLink"/>
	<br/>
					Comparison Link: <xsl:value-of select="$compareLink"/>
	<br/>
					Product Price: <xsl:value-of select="$prodPrice"/>
	<br/>
					Delivery Price: <xsl:value-of select="$delCost"/>
	<br/>
					New/Used: <xsl:value-of select="$prodState"/>
	<br/>
					Availabile: <xsl:value-of select="$prodAvail"/>
	<br/>
					Short Desc: <xsl:value-of select="substring(substring-before($prodDesc,'.'),1,1000)"/>
	<br/>
	<xsl:template match="Warnings"/>
	<xsl:template match="Categories/*"/>
	<xsl:template match="Products/Product/Offer/GridImage"/>
</xsl:stylesheet>

Open in new window

0
Geert BormansInformation ArchitectCommented:
CAn you please post the full XSLT, because it is filled again with cut and paste errors
0
Geert BormansInformation ArchitectCommented:
Well, I think you don't grasp the concept of templates

Templates are the building blocks of an XSLT
A node that requires processing picks the template that matches its pattern best
but in order to tell nodes that they require processing, you need to pass them using apply-templates.
All actions happen inside templates, operations outside templates are not allowed (and don't make sense)
Beware: XSLT is not procedural, so action happen as you progress through the XML data

I needed to restructure your XSLT entirely
You can use the Merchant/Name example as a basis for all the other thigs you need

- Variables in XSLT are not variables but constants and they don't live outside the scope they are created.
A variable created inside a template does not live outside that template
No need to use variables here, they are contraproductive

- your source is in a namespace
ProductSearch xmlns="urn:yahoo:prods" puts all descendants in the same namespace
in order to be able to prcess in XSLT, you need a namespace too, and since the output namespace is the default one in XSLT, you will need a prefix... all XPaths will need to be prefixed
<xsl:value-of select="yahoo:Merchant/yahoo:Name"/>

<?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" 
    xmlns:user="urn:comparionsplus-com:xslt"
    xmlns:yahoo="urn:yahoo:prods">
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html>
            <body>
                <xsl:apply-templates select="yahoo:ProductSearch/yahoo:Products"/>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="yahoo:ProductSearch/yahoo:Products">
            <xsl:for-each select="@*">
                   <xsl:value-of select="name()"/>
                   <xsl:text> : </xsl:text>
                   <xsl:value-of select="."/>
               <br/>
            </xsl:for-each>
        <xsl:apply-templates select="yahoo:Product/yahoo:Offer"/>
    </xsl:template>
    <xsl:template match="yahoo:Products/yahoo:Product/yahoo:Offer">
        <xsl:text>Merchant Name: </xsl:text>
        <xsl:value-of select="yahoo:Merchant/yahoo:Name"/>
        <br/>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
QuinnDesterAuthor Commented:
Thanks Gertone

I will try this in a little while if you dont mind, just bathing the kids ready for school in the morning

I have read lots about needing to include the name space but until now, didnt realise what the name space actualy was and where it was defined. that makes other problems i was having make much more sense,

thank you
0
QuinnDesterAuthor Commented:
Excellent, Thank you very much, and again for the explination.

seeing the part you did and the explination i can see what i need to do to move forward and have a better understanding now.
0
QuinnDesterAuthor Commented:
Excellent help complete with explination of where i was going wrong.
Thank you
0
Geert BormansInformation ArchitectCommented:
welcome, good luck
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.