Using xsl to display xml information using "value by reference"


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Using xsl to display xml information using "value by reference"

  1. #1
    Scott Guest

    Using xsl to display xml information using "value by reference"


    HELP!
    I have spent far to long researching this and can't find an answer. I am
    trying to display xml data using xsl stylesheets. However, I am trying to
    obtain values by reference rather than directly and can't seem to get it
    to work.
    Here is my xml:

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="Assign7.xsl"?>
    <family>
    <people>
    <person id="P01">Leslie</person>
    <person id="P02">Doris</person>
    <person id="P03">Werner</person>
    <person id="P04">Lillian</person>
    <person id="P05">James</person>
    <person id="P06">Shirley</person>
    <person id="P07">Kimberly</person>
    <person id="P08">Greg</person>
    <person id="P09">Scott</person>
    </people>
    <genList>
    <generation id="G1">GrandParents</generation>
    <generation id="G2">Parents</generation>
    <generation id="G3">Siblings</generation>
    </genList>
    <familySide>
    <side id="S1">Mother</side>
    <side id="S2">Father</side>
    </familySide>

    <familyTree>
    <member>
    <person idref="P01"/>
    <generation idref="G1"/>
    <side idref="S1"/>
    </member>
    <member>
    <person idref="P02"/>
    <generation idref="G1"/>
    <side idref="S1"/>
    </member>
    <member>
    <person idref="P03"/>
    <generation idref="G1"/>
    <side idref="S2"/>
    </member>
    <member>
    <person idref="P04"/>
    <generation idref="G1"/>
    <side idref="S2"/>
    </member>
    <member>
    <person idref="P05"/>
    <generation idref="G2"/>
    <side idref="S1"/>
    </member>
    <member>
    <person idref="P06"/>
    <generation idref="G2"/>
    <side idref="S2"/>
    </member>
    <member>
    <person idref="P07"/>
    <generation idref="G3"/>
    <side idref="S1"/>
    </member>
    <member>
    <person idref="P08"/>
    <generation idref="G3"/>
    <sidrefe idref="S1"/>
    </member>
    <member>
    <person idref="P09"/>
    <generation idref="G3"/>
    <side idref="S1"/>
    </member>
    </familyTree>

    </family>

    and this is my xsl so far:

    <?xml version="1.0" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.w3.org/TR/REC-html40">
    <xsl:template match="/">
    <html>
    <body>
    <table border="1" bgcolor="#80FF00" width="33%">
    <tr>
    <th>Generation</th>
    <th>Person</th>
    <th>Side</th>
    </tr>

    <xsl:for-each select="member">
    <tr>
    <td>
    <xsl:value-of select="generation/id(@idref)"/>
    </td>
    <td>
    <xsl:value-of select="person/id(@idref)"/>
    </td>
    <td>
    <xsl:value-of select="side/id(@idref)">
    </td>

    </tr>

    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    If you have any ideas I would greatly appreciate hearing from you.
    Thanks greatly, Scott


  2. #2
    Yoyo Guest

    Re: Using xsl to display xml information using "value by reference"


    try this xsl

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/">

    <html>
    <body>
    <table border="1" bgcolor="#80FF00" width="33%">
    <tr>
    <th>Generation</th>
    <th>Person</th>
    <th>Side</th>
    </tr>

    <xsl:for-each select="family/familyTree/member">
    <tr>
    <td><xsl:value-of select="generation/@idref"/></td>
    <td><xsl:value-of select="person/@idref"/></td>
    <td><xsl:value-of select="side/@idref"/></td>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>

    </xsl:template>

    </xsl:stylesheet>

  3. #3
    Steve Guest

    Re: Using xsl to display xml information using "value by reference"


    Scott,

    For the XSLT function id() to work, you must define the ID and IDREF fields
    in a DTD (I believe a schema will work, but I haven't tried it yet). Try
    adding the following DTD to your XML file and your application should work.
    There may be some problems with my DTD definition (schemas might more accurately
    describe your data), but this should give you something to go on. The bottom
    line is the XSLT processor must know which attributes are IDs and which are
    IDREFs.

    <!DOCTYPE family [
    <!ELEMENT family (people, genList, familySide, familyTree)>
    <!ELEMENT people (person*)>
    <!ELEMENT person (PCDATA)>
    <!ATTLIST person id ID #IMPLIED>
    <!ATTLIST person idref IDREF #IMPLIED>
    <!ELEMENT genList (generation*)>
    <!ELEMENT generation (PCDATA)>
    <!ATTLIST generation id ID #IMPLIED>
    <!ATTLIST generation idref IDREF #IMPLIED>
    <!ELEMENT familySide (side*)>
    <!ELEMENT side (PCDATA)>
    <!ATTLIST side id ID #IMPLIED>
    <!ATTLIST side idref IDREF #IMPLIED>
    <!ELEMENT familyTree (*member)>
    <!ELEMENT member (person, generation, side)>
    ]>

    Steve

    "Scott" <saroy71@hotmail.com> wrote:
    >
    >HELP!
    >I have spent far to long researching this and can't find an answer. I am
    >trying to display xml data using xsl stylesheets. However, I am trying to
    >obtain values by reference rather than directly and can't seem to get it
    >to work.
    >Here is my xml:
    >
    ><?xml version="1.0"?>
    ><?xml-stylesheet type="text/xsl" href="Assign7.xsl"?>
    ><family>
    > <people>
    > <person id="P01">Leslie</person>
    > <person id="P02">Doris</person>
    > <person id="P03">Werner</person>
    > <person id="P04">Lillian</person>
    > <person id="P05">James</person>
    > <person id="P06">Shirley</person>
    > <person id="P07">Kimberly</person>
    > <person id="P08">Greg</person>
    > <person id="P09">Scott</person>
    > </people>
    > <genList>
    > <generation id="G1">GrandParents</generation>
    > <generation id="G2">Parents</generation>
    > <generation id="G3">Siblings</generation>
    > </genList>
    > <familySide>
    > <side id="S1">Mother</side>
    > <side id="S2">Father</side>
    > </familySide>
    >
    > <familyTree>
    > <member>
    > <person idref="P01"/>
    > <generation idref="G1"/>
    > <side idref="S1"/>
    > </member>
    > <member>
    > <person idref="P02"/>
    > <generation idref="G1"/>
    > <side idref="S1"/>
    > </member>
    > <member>
    > <person idref="P03"/>
    > <generation idref="G1"/>
    > <side idref="S2"/>
    > </member>
    > <member>
    > <person idref="P04"/>
    > <generation idref="G1"/>
    > <side idref="S2"/>
    > </member>
    > <member>
    > <person idref="P05"/>
    > <generation idref="G2"/>
    > <side idref="S1"/>
    > </member>
    > <member>
    > <person idref="P06"/>
    > <generation idref="G2"/>
    > <side idref="S2"/>
    > </member>
    > <member>
    > <person idref="P07"/>
    > <generation idref="G3"/>
    > <side idref="S1"/>
    > </member>
    > <member>
    > <person idref="P08"/>
    > <generation idref="G3"/>
    > <sidrefe idref="S1"/>
    > </member>
    > <member>
    > <person idref="P09"/>
    > <generation idref="G3"/>
    > <side idref="S1"/>
    > </member>
    > </familyTree>
    >
    ></family>
    >
    >and this is my xsl so far:
    >
    ><?xml version="1.0" ?>
    ><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >xmlns="http://www.w3.org/TR/REC-html40">
    ><xsl:template match="/">
    ><html>
    ><body>
    ><table border="1" bgcolor="#80FF00" width="33%">
    > <tr>
    > <th>Generation</th>
    > <th>Person</th>
    > <th>Side</th>
    > </tr>
    >
    > <xsl:for-each select="member">
    > <tr>
    > <td>
    > <xsl:value-of select="generation/id(@idref)"/>
    > </td>
    > <td>
    > <xsl:value-of select="person/id(@idref)"/>
    > </td>
    > <td>
    > <xsl:value-of select="side/id(@idref)">
    > </td>
    >
    > </tr>
    >
    > </xsl:for-each>
    ></table>
    ></body>
    ></html>
    > </xsl:template>
    > </xsl:stylesheet>
    >
    >If you have any ideas I would greatly appreciate hearing from you.
    >Thanks greatly, Scott
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center