Jump to content

Replace some text node and sum


karamba
 Share

Recommended Posts

Hello,

I'm rather new in the xml world and I have a problem setting up an appropriate xslt to translate some node content into numeric values and to create a sum for each record.

Here's how the sample xml file looks like:

<record 1>	<title>title 1</title>	<note type="tags">		<note type="tag">text A</note>	</note></record><record 2>	<title>title 2</title>	<note type="tags">		<note type="tag">text A</note>		<note type="tag">text B</note>		<note type="tag">text C</note>	</note></record><record 3>	<title>title 3</title>	<note type="tags">		<note type="tag">text A</note>		<note type="tag">text C</note>	</note></record>

What I would like to do is to transform some of the "note" values into numeric values (for a database) and make one sum for each dataset.

"text A" should return "1"

"text B" should return "2"

"text C" should return "4" and so on resulting in something like this:

</Record 1><sum>1</sum></Record 1></Record 2><sum>7</sum></Record 2></Record 3><sum>5</sum></Record 3>

But I got stuck how to capture the values for each dataset for further processing, namely to create a sum for each.There is more information extracted from "note" values, which are simply compared to certain values with an <xsl: if test="contains(note, 'value')"> or <xsl: if ="starts with(note, 'value')"> outputting a numeric value as <xsl:text>. As can be seen below:

<xsl:choose>	<xsl:when test="note">		<xsl:choose>									  			<xsl:when test="contains(note, 'text y')">				<xsl:text>128</xsl:text>			</xsl:when>			<xsl:when test="contains(note, 'text z')">				<xsl:text>256</xsl:text>			</xsl:when></xsl:choose>

Could you help me? I am grateful for any suggestions.Thank you

Link to comment
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
 Share

×
×
  • Create New...