Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > small question about <xml:if>

Reply
Thread Tools

small question about <xml:if>

 
 
ina
Guest
Posts: n/a
 
      06-09-2006
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

 
Reply With Quote
 
 
 
 
ina
Guest
Posts: n/a
 
      06-09-2006
this is the xlts:

<?xml version='1.0' ?>
<xsl:stylesheet version="1.0"
xmlnssl="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


 
Reply With Quote
 
 
 
 
Andy Dingley
Guest
Posts: n/a
 
      06-09-2006
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


<xslutput 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>

 
Reply With Quote
 
ina
Guest
Posts: n/a
 
      06-09-2006

Andy Dingley <(E-Mail Removed)> 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
>
>
> <xslutput 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>


 
Reply With Quote
 
ina
Guest
Posts: n/a
 
      06-09-2006
Thanks Andy. It is a great help

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


I will try it.
Thanks

Ina
Andy Dingley <(E-Mail Removed)> 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
>
>
> <xslutput 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>


 
Reply With Quote
 
ina
Guest
Posts: n/a
 
      06-09-2006
Thanks Andy. It is a great help

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


I will try it.
Thanks

Ina
Andy Dingley <(E-Mail Removed)> 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
>
>
> <xslutput 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>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Small cameras getting too small? GRL Digital Photography 50 02-03-2006 03:12 AM
small question moonlight VHDL 1 01-16-2006 09:26 AM
Small Square with small red X Peter Coddington Computer Support 4 01-03-2006 06:58 AM
Small Question =?Utf-8?B?a2lzaG9y?= ASP .Net 2 08-19-2005 12:29 PM
Datagrid --> Excel Spreadsheet - A "small detail" question Dave ASP .Net 0 08-13-2004 08:04 PM



Advertisments