small question about <xml:if>

I

ina

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
 
I

ina

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

Andy Dingley

ina said:
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>
 
I

ina

Andy Dingley said:
ina said:
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>
 
I

ina

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 said:
ina said:
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>
 
I

ina

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 said:
ina said:
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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,002
Messages
2,570,261
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top