Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Need help with XSLT and element vs. attribute decisions.

    Hello everyone.

    I am new to XML, and here I am trying to construct some kind of catelog modelling a shop.

    If I put the link of a picture as an attribute in my XML file, how would I transform it into an attribute of an image tag with XSLT. So I would like to render my XML file into XSLT. This is something I have:

    <product imgsrc="1.jpg">
    <Name>Crap</Name>
    ...
    </product>

    And I would like to take this link, "1.jpg", and put it as an image in the xhtml file generated by XSLT.

    In addition, I have no idea of what to put as element and what to put as attribute. This is a rough list of things that I have for my XML:

    catelog, product (w/ ID, name, imgsrc, description, category, availability, width/height i.e. dimension)

    ID would be an attribute to the product tag, but what about category and availability? It seems that avail. can be denoted by a number, say 0 and 1, and the user doesn't necessarily need to know what the code stands for. As name is an element, show category be an element too?

    Finally, should width/height be elements of the dimension tag, as elements of just the product tag, or width/height be attributes to the dimension tag (which is an element of product)?

    Thank you very much, and I look foward to some suggestions.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Newcastle, England
    Posts
    178
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    If you are that new to XML/XSLT can I suggest that you visit the Learn XSL tutorials at http://www.w3schools.com/ You'll learn so much there in an hour or so that might take days of posting questions.

    good luck

    patrick

  • #3
    New to the CF scene
    Join Date
    Oct 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks for the link, and I got the first question.

    Thanks for the link. Just so anyone wants to try this, here is the code I wrote:

    test.xml:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="test.xsl"?>
    <img src="carter.jpg" />

    test.xsl:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xslutput method="html"/>
    <xsl:template match="/img">
    <html>
    <head><title>Testing</title></head>
    <body>
    <img>
    <xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>
    </img>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    Ugly indentation here... xsl:attribute does the magic!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •