small question about <xml:if>

Discussion in 'XML' started by ina, Jun 9, 2006.

  1. ina

    ina Guest

    Hello guys,

    My name is ina and I have a problem with a file xlst. I am newbie and
    sorry for this question, probably must be very simple.

    I have this xml file

    <?xml version="1.0"?>
    <Datasource>
    <cars><car><car_Short_Name>OPEL</car_Short_Name><car_Contracts><CtoF_Contract
    From_Date="" To_Date="">
    <CtoF_Contract_Type Type="Administrator"/>
    <Company_FID>Company_204736</Company_FID>
    </CtoF_Contract>
    </car_Contracts>
    <car_Contracts><CtoF_Contract From_Date="" To_Date="">
    <CtoF_Contract_Type Type="Firm"/>
    <Company_FID>Company_204730</Company_FID>
    </CtoF_Contract>
    </car_Contracts>
    </car>
    </cars><Companies>
    <Company>
    <Company_FID>Company_204730</Company_FID>
    <Company_Legal_Name From_Date="" To_Date="">
    <Company_Name>HHLXC Management AG</Company_Name>
    <Legal_Type>Unknown</Legal_Type>
    </Company_Legal_Name>
    <Legal_Domicile From_Date="" To_Date="">
    <Country>CH</Country>
    </Legal_Domicile>
    <Web_Site From_Date="" To_Date="">www.company.com</Web_Site>
    <Site Main="Yes">
    <Address From_Date="" To_Date="">
    <Street>Caille</Street>
    <City>Mexico city</City>
    <ZIP_City>6301ff</ZIP_City>
    <Country>Mexico</Country>
    </Address>
    <Site_Communication>
    <Phone From_Date="" To_Date=""></Phone>
    <Fax From_Date="" To_Date=""></Fax>
    <E-mail From_Date="" To_Date=""></E-mail>
    </Site_Communication>
    </Site>
    <Site Main="No">
    <Address From_Date="" To_Date="">
    <Street></Street>
    <City></City>
    <ZIP_City></ZIP_City>
    <State></State>
    <Country></Country>
    </Address>
    <Site_Communication>
    <Phone From_Date="" To_Date=""></Phone>
    <Fax From_Date="" To_Date=""></Fax>
    </Site_Communication>
    </Site>
    </Company>
    <Company>
    <Company_FID>Company_204736</Company_FID>
    <Company_Legal_Name From_Date="" To_Date="">
    <Company_Name>HHC International, Ltd.</Company_Name>
    <Legal_Type>Unknown</Legal_Type>
    </Company_Legal_Name>
    </Company>
    </Companies></Datasource>

    and I am trying to use in xlts <xml:if> but with no success. I would
    like to do it is to find the company information for each company ID in
    car and type of contract.

    I would like to have these results with xlts

    <cars>
    <car_name>OPEL></car_name>
    <administrator>HHC International, Ltd</administrator>
    <domicile></domicile>
    <Firm>HHLXC Management AG</Firm>
    <domicile>Mexico</domicile>
    </cars>

    any suggestions
    ina, Jun 9, 2006
    #1
    1. Advertising

  2. ina

    ina Guest

    this is the xlts:

    <?xml version='1.0' ?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <xsl:for-each select="Datasource/cars/car/car_Short_Name">
    <cars>
    <xsl:value-of select="."/>
    </cars>
    </xsl:for-each>
    <xsl:for-each
    select="Datasource/cars/car/car_Contracts/CtoF_Contract/Company_FID">
    <administrator>
    <xsl:if test=". = ../../../../../Companies/Company/Company_FID">
    <xsl:value-of
    select="../../../../../Companies/Company/Company_Legal_Name/Company_Name"/>
    </xsl:if>
    </administrator>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    Ina
    ina wrote:
    > Hello guys,
    >
    > My name is ina and I have a problem with a file xlst. I am newbie and
    > sorry for this question, probably must be very simple.
    >
    > I have this xml file
    >
    > <?xml version="1.0"?>
    > <Datasource>
    > <cars><car><car_Short_Name>OPEL</car_Short_Name><car_Contracts><CtoF_Contract
    > From_Date="" To_Date="">
    > <CtoF_Contract_Type Type="Administrator"/>
    > <Company_FID>Company_204736</Company_FID>
    > </CtoF_Contract>
    > </car_Contracts>
    > <car_Contracts><CtoF_Contract From_Date="" To_Date="">
    > <CtoF_Contract_Type Type="Firm"/>
    > <Company_FID>Company_204730</Company_FID>
    > </CtoF_Contract>
    > </car_Contracts>
    > </car>
    > </cars><Companies>
    > <Company>
    > <Company_FID>Company_204730</Company_FID>
    > <Company_Legal_Name From_Date="" To_Date="">
    > <Company_Name>HHLXC Management AG</Company_Name>
    > <Legal_Type>Unknown</Legal_Type>
    > </Company_Legal_Name>
    > <Legal_Domicile From_Date="" To_Date="">
    > <Country>CH</Country>
    > </Legal_Domicile>
    > <Web_Site From_Date="" To_Date="">www.company.com</Web_Site>
    > <Site Main="Yes">
    > <Address From_Date="" To_Date="">
    > <Street>Caille</Street>
    > <City>Mexico city</City>
    > <ZIP_City>6301ff</ZIP_City>
    > <Country>Mexico</Country>
    > </Address>
    > <Site_Communication>
    > <Phone From_Date="" To_Date=""></Phone>
    > <Fax From_Date="" To_Date=""></Fax>
    > <E-mail From_Date="" To_Date=""></E-mail>
    > </Site_Communication>
    > </Site>
    > <Site Main="No">
    > <Address From_Date="" To_Date="">
    > <Street></Street>
    > <City></City>
    > <ZIP_City></ZIP_City>
    > <State></State>
    > <Country></Country>
    > </Address>
    > <Site_Communication>
    > <Phone From_Date="" To_Date=""></Phone>
    > <Fax From_Date="" To_Date=""></Fax>
    > </Site_Communication>
    > </Site>
    > </Company>
    > <Company>
    > <Company_FID>Company_204736</Company_FID>
    > <Company_Legal_Name From_Date="" To_Date="">
    > <Company_Name>HHC International, Ltd.</Company_Name>
    > <Legal_Type>Unknown</Legal_Type>
    > </Company_Legal_Name>
    > </Company>
    > </Companies></Datasource>
    >
    > and I am trying to use in xlts <xml:if> but with no success. I would
    > like to do it is to find the company information for each company ID in
    > car and type of contract.
    >
    > I would like to have these results with xlts
    >
    > <cars>
    > <car_name>OPEL></car_name>
    > <administrator>HHC International, Ltd</administrator>
    > <domicile></domicile>
    > <Firm>HHLXC Management AG</Firm>
    > <domicile>Mexico</domicile>
    > </cars>
    >
    > any suggestions
    ina, Jun 9, 2006
    #2
    1. Advertising

  3. ina

    Andy Dingley Guest

    ina wrote:

    > like to do it is to find the company information for each company ID in
    > car and type of contract.


    Try this. It's not great code, but it should be readable. Making it
    better would need more information, particularly about error handling,
    handling changes of address etc. It could get to be quite complex.

    The XML schema is also less well-designed than it could be. Be generous
    with container elements to wrap up related items, be careful with case,
    be careful with plurals


    <xsl:eek:utput method ="xml" indent="yes" />

    <xsl:template match="/">

    <cars>
    <xsl:for-each select="/Datasource/cars/car">
    <!--
    You'd be better with a <car> container element here
    <car>
    -->
    <car_name><xsl:value-of select="./car_Short_Name"
    /></car_name>


    <xsl:for-each select="./car_Contracts">
    <xsl:variable name="contract" select="." />
    <xsl:variable name="contract-type"
    select="$contract/CtoF_Contract/CtoF_Contract_Type/@Type" />
    <xsl:variable name="company"
    select="/Datasource/Companies/Company [Company_FID =
    $contract/CtoF_Contract/Company_FID] " />

    <xsl:choose>
    <xsl:when test="$contract-type = 'Administrator'" >
    <administrator><xsl:value-of
    select="$company/Company_Legal_Name/Company_Name" /></administrator>
    </xsl:when>

    <xsl:when test="$contract-type = 'Firm'" >
    <Firm><xsl:value-of select="$company/Company_Legal_Name/Company_Name"
    /></Firm>
    </xsl:when>
    </xsl:choose>

    <domicile><xsl:value-of select="$company/Site [@Main='Yes']
    /Address/Country" /></domicile>
    </xsl:for-each>

    <!-- </car> -->
    </xsl:for-each>
    </cars>
    </xsl:template>
    Andy Dingley, Jun 9, 2006
    #3
  4. ina

    ina Guest

    Andy Dingley <> wrote:
    > ina wrote:
    >
    > > like to do it is to find the company information for each company ID in
    > > car and type of contract.

    >
    > Try this. It's not great code, but it should be readable. Making it
    > better would need more information, particularly about error handling,
    > handling changes of address etc. It could get to be quite complex.
    >
    > The XML schema is also less well-designed than it could be. Be generous
    > with container elements to wrap up related items, be careful with case,
    > be careful with plurals
    >
    >
    > <xsl:eek:utput method ="xml" indent="yes" />
    >
    > <xsl:template match="/">
    >
    > <cars>
    > <xsl:for-each select="/Datasource/cars/car">
    > <!--
    > You'd be better with a <car> container element here
    > <car>
    > -->
    > <car_name><xsl:value-of select="./car_Short_Name"
    > /></car_name>
    >
    >
    > <xsl:for-each select="./car_Contracts">
    > <xsl:variable name="contract" select="." />
    > <xsl:variable name="contract-type"
    > select="$contract/CtoF_Contract/CtoF_Contract_Type/@Type" />
    > <xsl:variable name="company"
    > select="/Datasource/Companies/Company [Company_FID =
    > $contract/CtoF_Contract/Company_FID] " />
    >
    > <xsl:choose>
    > <xsl:when test="$contract-type = 'Administrator'" >
    > <administrator><xsl:value-of
    > select="$company/Company_Legal_Name/Company_Name" /></administrator>
    > </xsl:when>
    >
    > <xsl:when test="$contract-type = 'Firm'" >
    > <Firm><xsl:value-of select="$company/Company_Legal_Name/Company_Name"
    > /></Firm>
    > </xsl:when>
    > </xsl:choose>
    >
    > <domicile><xsl:value-of select="$company/Site [@Main='Yes']
    > /Address/Country" /></domicile>
    > </xsl:for-each>
    >
    > <!-- </car> -->
    > </xsl:for-each>
    > </cars>
    > </xsl:template>
    ina, Jun 9, 2006
    #4
  5. ina

    ina Guest

    Thanks Andy. It is a great help :D

    I am newbie in XML and I do not know the grammar very well.


    I will try it.
    Thanks

    Ina
    Andy Dingley <> wrote:
    > ina wrote:
    >
    > > like to do it is to find the company information for each company ID in
    > > car and type of contract.

    >
    > Try this. It's not great code, but it should be readable. Making it
    > better would need more information, particularly about error handling,
    > handling changes of address etc. It could get to be quite complex.
    >
    > The XML schema is also less well-designed than it could be. Be generous
    > with container elements to wrap up related items, be careful with case,
    > be careful with plurals
    >
    >
    > <xsl:eek:utput method ="xml" indent="yes" />
    >
    > <xsl:template match="/">
    >
    > <cars>
    > <xsl:for-each select="/Datasource/cars/car">
    > <!--
    > You'd be better with a <car> container element here
    > <car>
    > -->
    > <car_name><xsl:value-of select="./car_Short_Name"
    > /></car_name>
    >
    >
    > <xsl:for-each select="./car_Contracts">
    > <xsl:variable name="contract" select="." />
    > <xsl:variable name="contract-type"
    > select="$contract/CtoF_Contract/CtoF_Contract_Type/@Type" />
    > <xsl:variable name="company"
    > select="/Datasource/Companies/Company [Company_FID =
    > $contract/CtoF_Contract/Company_FID] " />
    >
    > <xsl:choose>
    > <xsl:when test="$contract-type = 'Administrator'" >
    > <administrator><xsl:value-of
    > select="$company/Company_Legal_Name/Company_Name" /></administrator>
    > </xsl:when>
    >
    > <xsl:when test="$contract-type = 'Firm'" >
    > <Firm><xsl:value-of select="$company/Company_Legal_Name/Company_Name"
    > /></Firm>
    > </xsl:when>
    > </xsl:choose>
    >
    > <domicile><xsl:value-of select="$company/Site [@Main='Yes']
    > /Address/Country" /></domicile>
    > </xsl:for-each>
    >
    > <!-- </car> -->
    > </xsl:for-each>
    > </cars>
    > </xsl:template>
    ina, Jun 9, 2006
    #5
  6. ina

    ina Guest

    Thanks Andy. It is a great help :D

    I am newbie in XML and I do not know the grammar very well.


    I will try it.
    Thanks

    Ina
    Andy Dingley <> wrote:
    > ina wrote:
    >
    > > like to do it is to find the company information for each company ID in
    > > car and type of contract.

    >
    > Try this. It's not great code, but it should be readable. Making it
    > better would need more information, particularly about error handling,
    > handling changes of address etc. It could get to be quite complex.
    >
    > The XML schema is also less well-designed than it could be. Be generous
    > with container elements to wrap up related items, be careful with case,
    > be careful with plurals
    >
    >
    > <xsl:eek:utput method ="xml" indent="yes" />
    >
    > <xsl:template match="/">
    >
    > <cars>
    > <xsl:for-each select="/Datasource/cars/car">
    > <!--
    > You'd be better with a <car> container element here
    > <car>
    > -->
    > <car_name><xsl:value-of select="./car_Short_Name"
    > /></car_name>
    >
    >
    > <xsl:for-each select="./car_Contracts">
    > <xsl:variable name="contract" select="." />
    > <xsl:variable name="contract-type"
    > select="$contract/CtoF_Contract/CtoF_Contract_Type/@Type" />
    > <xsl:variable name="company"
    > select="/Datasource/Companies/Company [Company_FID =
    > $contract/CtoF_Contract/Company_FID] " />
    >
    > <xsl:choose>
    > <xsl:when test="$contract-type = 'Administrator'" >
    > <administrator><xsl:value-of
    > select="$company/Company_Legal_Name/Company_Name" /></administrator>
    > </xsl:when>
    >
    > <xsl:when test="$contract-type = 'Firm'" >
    > <Firm><xsl:value-of select="$company/Company_Legal_Name/Company_Name"
    > /></Firm>
    > </xsl:when>
    > </xsl:choose>
    >
    > <domicile><xsl:value-of select="$company/Site [@Main='Yes']
    > /Address/Country" /></domicile>
    > </xsl:for-each>
    >
    > <!-- </car> -->
    > </xsl:for-each>
    > </cars>
    > </xsl:template>
    ina, Jun 9, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jimmy Zhang
    Replies:
    1
    Views:
    304
    Enrique
    May 19, 2004
  2. Simon Harvey
    Replies:
    12
    Views:
    633
    Chris Barber
    Jul 30, 2003
  3. Roberto Nunnari

    new small xml parser Open Source

    Roberto Nunnari, Feb 2, 2004, in forum: XML
    Replies:
    0
    Views:
    444
    Roberto Nunnari
    Feb 2, 2004
  4. deepak

    small xml question

    deepak, Jan 11, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    277
    Hans Kesting
    Jan 14, 2008
  5. Erik Wasser
    Replies:
    5
    Views:
    445
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page