Jump to content

XSL: only display names that end with ium

Blackterror25

I've got an instruction from my teacher to do a couple of things with the periodic table content in xsl.

 

I'm currently stuck on something that I've been trying to fix for a couple of houres and was hopen some of you could help me.
I should only display the elements that end with ium.

 

the xml file looks like this:

<periodic_table>  <atom>    <name>Actinium</name>    <atomic_weight>227</atomic_weight>    <atomic_number>89</atomic_number>    <oxidation_states>3</oxidation_states>    <boiling_point units="Kelvin">3470</boiling_point>    <symbol>Ac</symbol>    <density units="grams/cubic centimeter"><!-- At 300K -->      10.07    </density>    <electron_configuration>[Rn] 6d1 7s2 </electron_configuration>    <electronegativity>1.1</electronegativity>    <atomic_radius units="Angstroms">1.88</atomic_radius>    <atomic_volume units="cubic centimeters/mole">      22.5    </atomic_volume>    <specific_heat_capacity units="Joules/gram/degree Kelvin">      0.12    </specific_heat_capacity>    <ionization_potential>5.17</ionization_potential>    <thermal_conductivity units="Watts/meter/degree Kelvin">    <!-- At 300K -->      12    </thermal_conductivity>  </atom>  <atom>    <name>Aluminum</name>    <atomic_weight>26.98154</atomic_weight>    <atomic_number>13</atomic_number>    <oxidation_states>3</oxidation_states>    <boiling_point units="Kelvin">2740</boiling_point>    <melting_point units="Kelvin">933.5</melting_point>    <symbol>Al</symbol>    <density units="grams/cubic centimeter"><!-- At 300K -->      2.7    </density>    <electron_configuration>[Ne] 3s2 p1 </electron_configuration>    <covalent_radius units="Angstroms">1.18</covalent_radius>    <electronegativity>1.61</electronegativity>    <atomic_radius units="Angstroms">1.43</atomic_radius>    <heat_of_vaporization units="kilojoules/mole">      290.8    </heat_of_vaporization>    <atomic_volume units="cubic centimeters/mole">      10    </atomic_volume>    <heat_of_fusion units="kilojoules/mole">      10.7    </heat_of_fusion>    <ionization_potential>5.986</ionization_potential>    <specific_heat_capacity units="Joules/gram/degree Kelvin">      0.9    </specific_heat_capacity>    <thermal_conductivity units="Watts/meter/degree Kelvin">    <!-- At 300K -->      237    </thermal_conductivity>  </atom>...</periodic_table

Thanks for having a look and helping me.

(\__/)

(='.'=)

(")_(") This is Bunny.

Link to comment
Share on other sites

Link to post
Share on other sites

Deserialise it into an object.

Loop through those objects and print ones that match a regular expression.

 

Simple.

Link to comment
Share on other sites

Link to post
Share on other sites

Deserialise it into an object.

Loop through those objects and print ones that match a regular expression.

 

Simple.

I already figured that part out but I was more having troubles with how excaclty to code it that it only checked the last  letters and then print out the names.

(\__/)

(='.'=)

(")_(") This is Bunny.

Link to comment
Share on other sites

Link to post
Share on other sites

I already figured that part out but I was more having troubles with how excaclty to code it that it only checked the last  letters and then print out the names.

What language?

Link to comment
Share on other sites

Link to post
Share on other sites

What language?

xsl

specificly with only showing those that end with -ium, no problem with showing alle the names.

Its probably really simple but i've only been coding for 2 months.

(\__/)

(='.'=)

(")_(") This is Bunny.

Link to comment
Share on other sites

Link to post
Share on other sites

xsl

specificly with only showing those that end with -ium, no problem with showing alle the names.

Its probably really simple but i've only been coding for 2 months.

Have a look at this:

http://www.xml.com/pub/a/2003/06/04/tr.html

 

The regular expression you need is

[a-z]{1,}ium
Link to comment
Share on other sites

Link to post
Share on other sites

 

The regular expression you need is

[a-z]{1,}ium

 

To make this work if the XML file has capital letters in the names as well, you can simply modify this to

[a-zA-Z]{1,}ium

Also, I think (not entirely sure), that this should work as well:

[a-zA-Z]+ium[a-zA-Z]*ium

The first will require at least one letter in front of ium, the second sees ium on its own as a valid option as well.

Link to comment
Share on other sites

Link to post
Share on other sites

To make this work if the XML file has capital letters in the names as well, you can simply modify this to

[a-zA-Z]{1,}ium

Also, I think (not entirely sure), that this should work as well:

[a-zA-Z]+ium

[a-zA-Z]*ium

The first will require at least one letter in front of ium, the second sees ium on its own as a valid option as well.

 

 

 

I can't for the life of me figure out how to add that to the xsl file. I currently made a template where I believe I should add it somewhere, but I cant figure out where.

 

This is what I currently have.

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0"                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">    <xsl:template match="/">        <html>            <body>                <xsl:apply-templates/>            </body>        </html>    </xsl:template>    <xsl:template match="name">    </xsl:template></xsl:stylesheet> 

(\__/)

(='.'=)

(")_(") This is Bunny.

Link to comment
Share on other sites

Link to post
Share on other sites

I figured it out by trying something different

                <xsl:for-each select="periodic_table/atom">                    <xsl:if test="substring(name, string-length(name) - 2, string-length(name))='ium'">                        <xsl:value-of select="name" />                        <br/>                    </xsl:if>                </xsl:for-each>

Thank you for your help.

(\__/)

(='.'=)

(")_(") This is Bunny.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×