zoltan_ie
October 2nd, 2003, 07:12 AM
I'm total new to XSLT and I've just about given up looking on the web for a decent tutorial.
<source>
<instance>
<fragment label="1">42</fragment>
<fragment label="2">THE</fragment>
<fragment label="3">HEATH</fragment>
<fragment label="4">CYPRESS</fragment>
<fragment label="5">DOWNS</fragment>
<fragment label="6">DUBLIN</fragment>
<fragment label="7">6</fragment>
<fragment label="8">DUBLIN</fragment>
</instance>
<instance>
<fragment label="9">39</fragment>
<fragment label="10">KILCARN</fragment>
<fragment label="11">COURT</fragment>
<fragment label="12">NAVAN</fragment>
<fragment label="13">MEATH</fragment>
</instance>
</source>
<source>
<instance>
<organisation_name>42</organisation_name>
<sub_building>THE</sub_building>
<building_name>HEATH</building_name>
<building_number>CYPRESS</building_number>
<street>DOWNS</street>
<street_pre>DUBLIN</street_pre>
<street_body>6</street_body>
<street_post>DUBLIN</street_post>
</instance>
<instance>
<locality>39</locality>
<county>KILCARN</county>
<county_area_subcode>COURT</county_area_subcode>
<country>NAVAN</country>
<invalid>MEATH</invalid>
</instance>
</source>
where
1 = organisation_name
2 = sub_building
3 = building_name
4 = building_number
5 = street
6 = street_pre
7 = street_body
8 = street_post
9 = locality
10 = county
11 = county_area_subcode
12 = country
13 = invalid
My lame attempt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<xsl:for-each select="//instance">
<xsl:for-each select="//fragment">
<xsl:if match="1 = @label">
<xsl:text>
<organisation_name>
<xsl:value-of select="//fragment"/>
</organisation_name>
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
can any one help me?
or can anyone tell me to use xsl:if or any of the other conditional statements properly. As in how to check string values agains another string value.
These are the only good sites I found but had no luck with them
http://www.zvon.org/xxl/XSLTutorial/Books/Output/index.html
http://www.w3schools.com/xsl/default.asp
Does any one know any other good ones?
<source>
<instance>
<fragment label="1">42</fragment>
<fragment label="2">THE</fragment>
<fragment label="3">HEATH</fragment>
<fragment label="4">CYPRESS</fragment>
<fragment label="5">DOWNS</fragment>
<fragment label="6">DUBLIN</fragment>
<fragment label="7">6</fragment>
<fragment label="8">DUBLIN</fragment>
</instance>
<instance>
<fragment label="9">39</fragment>
<fragment label="10">KILCARN</fragment>
<fragment label="11">COURT</fragment>
<fragment label="12">NAVAN</fragment>
<fragment label="13">MEATH</fragment>
</instance>
</source>
<source>
<instance>
<organisation_name>42</organisation_name>
<sub_building>THE</sub_building>
<building_name>HEATH</building_name>
<building_number>CYPRESS</building_number>
<street>DOWNS</street>
<street_pre>DUBLIN</street_pre>
<street_body>6</street_body>
<street_post>DUBLIN</street_post>
</instance>
<instance>
<locality>39</locality>
<county>KILCARN</county>
<county_area_subcode>COURT</county_area_subcode>
<country>NAVAN</country>
<invalid>MEATH</invalid>
</instance>
</source>
where
1 = organisation_name
2 = sub_building
3 = building_name
4 = building_number
5 = street
6 = street_pre
7 = street_body
8 = street_post
9 = locality
10 = county
11 = county_area_subcode
12 = country
13 = invalid
My lame attempt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<xsl:for-each select="//instance">
<xsl:for-each select="//fragment">
<xsl:if match="1 = @label">
<xsl:text>
<organisation_name>
<xsl:value-of select="//fragment"/>
</organisation_name>
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
can any one help me?
or can anyone tell me to use xsl:if or any of the other conditional statements properly. As in how to check string values agains another string value.
These are the only good sites I found but had no luck with them
http://www.zvon.org/xxl/XSLTutorial/Books/Output/index.html
http://www.w3schools.com/xsl/default.asp
Does any one know any other good ones?