#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2009
    Posts
    205
    Rep Power
    29

    Xml field with multi parts


    Hi,

    If you have a category field is there away of putting more then one category in it, so...

    <cat>cat 1, cat 2</cat>

    or

    <cat>cat 1 > cat 2</cat>

    or is it best to do:

    <cat>cat 1</cat>
    <cat>cat 2</cat>
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    The appropriate way to model it is:
    <cat>cat 1</cat>
    <cat>cat 2</cat>
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2009
    Posts
    205
    Rep Power
    29
    Thanks I will use that structure.

    Erm just wondering as the 2 fields have the same name will that cause any problems?

    Example:

    1 record with,

    <cat>red</cat>
    <cat>blue</cat>

    another record with,

    <cat>red</cat>
    <cat>green</cat>

    I have a page which is grabbing all records where the cat is red, will it grab both records?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    191
    Rep Power
    49
    you will use xpath


    example

    Code:
    <?xml version="1.0"?>
    <petshop>
    	<home>
    		<cat>Furby</cat>
    		<cat>Bonny</cat>
    		<cat>Sky</cat>
    		<cat>Smoky</cat>
    		<cat>Joey</cat>
    		<cat>Luky</cat>
    		<cat>*****</cat>
    		<cat>Twiety</cat>
    	</home>
    	<shop>
    		<cat>Furby</cat>
    		<cat>Bonny</cat>
    		<cat>Sky</cat>
    	</shop>
    </petshop>
    then you can select
    by example xsl

    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output indent="yes"/>
    	<xsl:template match="/">
    		<root>
    			<xsl:apply-templates select="petshop"/>
    		</root>
    	</xsl:template>
    	<xsl:template match="petshop">
    		<xsl:apply-templates select="home"/>
    	</xsl:template>
    	<xsl:template match="home">
    		<first>
    			<xsl:apply-templates select="cat[1]"/>
    		</first>
    		<last>
    			<xsl:apply-templates select="cat[last()]"/>
    		</last>
    		<all>
    			<xsl:apply-templates select="cat"/>
    		</all>
    		<allinfile>
    			<xsl:apply-templates select="..//cat"/>
    		</allinfile>
    	</xsl:template>
    	<xsl:template match="cat">
    		<select>
    			<xsl:value-of select="."/>
    		</select>
    	</xsl:template>
    </xsl:stylesheet>
    result xm
    Code:
    <?xml version='1.0' ?>
    <root>
      <first>
        <select>Furby</select>
      </first>
      <last>
        <select>Twiety</select>
      </last>
      <all>
        <select>Furby</select>
        <select>Bonny</select>
        <select>Sky</select>
        <select>Smoky</select>
        <select>Joey</select>
        <select>Luky</select>
        <select>*****</select>
        <select>Twiety</select>
      </all>
      <allinfile>
        <select>Furby</select>
        <select>Bonny</select>
        <select>Sky</select>
        <select>Smoky</select>
        <select>Joey</select>
        <select>Luky</select>
        <select>*****</select>
        <select>Twiety</select>
        <select>Furby</select>
        <select>Bonny</select>
        <select>Sky</select>
      </allinfile>
    </root>
    you all cat selected
    Helmut Hagemann Germany

    fallen to the bottom of the facts?
    I reach my hand and we go together


    wer lesen und google kann ist klar im Vorteil
    who read and google is able is clear in the advantage

IMN logo majestic logo threadwatch logo seochat tools logo