468,249 Members | 1,494 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,249 developers. It's quick & easy.

small question about <xml:if>

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

Jun 9 '06 #1
5 1059
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>

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


Jun 9 '06 #2
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:output 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>

Jun 9 '06 #3
ina

Andy Dingley <di*****@codesmiths.com> 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:output 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>


Jun 9 '06 #4
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 <di*****@codesmiths.com> 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:output 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>


Jun 9 '06 #5
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 <di*****@codesmiths.com> 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:output 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>


Jun 9 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by yzzzzz | last post: by
16 posts views Thread by Mike | last post: by
12 posts views Thread by bissatch | last post: by
2 posts views Thread by websls | last post: by
5 posts views Thread by Luke Vogel | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.