Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 10 of 10

Thread: Silly xslt problem - can anyone help?

  1. #1
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default Silly xslt problem - can anyone help?

    Hi All,

    I've been banging my head off my keyboard for hours & am stumped - can you offer any assistance?


    I have a simple xmlpackage & this line isn't working :-

    C#/VB.NET Code:
    <xsl:for-each select="/root/ProductCategories/Product[PID = $ProdID]"
    If I hard code the value like this it works :-

    C#/VB.NET Code:
    <xsl:for-each select="/root/ProductCategories/Product[PID = '409']"
    (I know that $ProdID = 409)

    I've tried all of the following & none of them work :-

    C#/VB.NET Code:
    <xsl:for-each select="/root/ProductCategories/Product[PID = $ProdID]">
    <
    xsl:for-each select="/root/ProductCategories/Product[PID = '$ProdID']">
    <
    xsl:for-each select="/root/ProductCategories/Product[PID = '{$ProdID}']">
    <
    xsl:for-each select="/root/ProductCategories/Product[PID = 'ProdID']"

    What am I missing?


    TTFN

    BFG

  2. #2
    Skriver is offline Senior Member
    Join Date
    Apr 2012
    Posts
    188

    Default

    Have you tried ProductID

  3. #3
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Yup - still no joy...

  4. #4
    Skriver is offline Senior Member
    Join Date
    Apr 2012
    Posts
    188

    Default

    I thought one of these may have worked

    <xsl:for-each select="/root/ProductCategories/Product[productid=$PID]">


    <xsl:for-each select="/root/ProductCategories/[productid=$PID]">

  5. #5
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    The fact that this works :-
    C#/VB.NET Code:
    <xsl:for-each select="/root/ProductCategories/Product[PID = '409']"
    Means that the part in red here MUST be right :-

    <xsl:for-each select="/root/ProductCategories/Product[PID = '409']">


    The only thing I can think of is that it's trying to compare a string to a number - not sure how to fix that though?


    TTFN

    BFG
    Last edited by BFG 9000; 05-04-2012 at 01:49 AM.

  6. #6
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Here's a snippet from the returned xml :-


    C#/VB.NET Code:
      <ProductCategories>
        <
    Product>
          <
    PID>133</PID>
          <
    CATID>26</CATID>
          <
    CATNAME>Road Safety </CATNAME>
          <
    CATSENAME>road-safety</CATSENAME>
        </
    Product>
        <
    Product>
          <
    PID>133</PID>
          <
    CATID>192</CATID>
          <
    CATNAME>Road Safety</CATNAME>
          <
    CATSENAME>road-safety</CATSENAME>
        </
    Product>
        <
    Product>
          <
    PID>409</PID>
          <
    CATID>238</CATID>
          <
    CATNAME>Office and Computing</CATNAME>
          <
    CATSENAME>office-and-computing</CATSENAME>
        </
    Product>
        <
    Product>
          <
    PID>409</PID>
          <
    CATID>239</CATID>
          <
    CATNAME>Computer Accessories</CATNAME>
          <
    CATSENAME>computer-accessories</CATSENAME>
        </
    Product>
        <
    Product>
          <
    PID>409</PID>
          <
    CATID>240</CATID>
          <
    CATNAME>Accessories For Laptop &ampNotebook PC's</CATNAME>
          <CATSENAME>accessories-for-laptop-notebook-pcs</CATSENAME>
        </Product>
        <Product>
          <PID>409</PID>
          <CATID>264</CATID>
          <CATNAME>SALE! Special Offers</CATNAME>
          <CATSENAME>sale-special-offers</CATSENAME>
        </Product> 

  7. #7
    webopius is offline Senior Member
    Join Date
    Nov 2008
    Location
    London, UK
    Posts
    440

    Default

    Just for my sanity, can you add a line to show the value of $PID just before you run the select?

    e.g.
    Code:
    <xsl:value-of select="$PID"/>
    At least then we'll know it has a value against which to filter the products against.

  8. #8
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    $PID doesn't actually relate to anything...


    PID is in the xml I'm trying to match.

    ????



    TTFN

    BFG

  9. #9
    webopius is offline Senior Member
    Join Date
    Nov 2008
    Location
    London, UK
    Posts
    440

    Default

    Sorry, me being an idiot - I copied the $PID from Skriver's post above!

    What I meant of course was: $ProdID

    <xsl:value-of select="$ProdID"/>

    Just to make sure it contains a value

  10. #10
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Mate, now I feel stupid.


    For some reason - this xmlpackage (unlike every other I've written) calls productid in the SQL query rather than ProductID.

    So when I tried to set $ProdID with this : <xsl:param name="ProdID" select="ProductID" /> it obviously failed - changed it to this : <xsl:param name="ProdID" select="productid" /> & it all works as expected now.

    In summary - you're awesome & I'm an arse.


    Cheers!!!