Hi i have xml file with nodes that could hold any type of input:

for example

XML code:
<Code>1.2.3</Code>
<name>John</name>
</Employee>
<Code>11.2.4</Code>
<name>John</name>
</Employee>
<Code>2.3.7</Code>
<name>John</name>
</Employee>

OR

<Code>a.1.5</Code>
<name>John</name>
</Employee>
<Code>a.2.1</Code>
<name>John</name>
</Employee>
<Code>c.4.2</Code>
<name>John</name>
</Employee>


The problem is that i can get any type of input

Im looking for a way to tokenize the input and compare each token based on its type...

How can i do it (or how can i do the sort with other method???)

i need to sort with xslt (xsl file)

Thanks ahead

Daniel

Recommended Answers

All 2 Replies

<?xml version="1.0"?>
<Employees>
	<Employee>
		<Code>1.2.3</Code>
		<name>John</name>
	</Employee>
	<Employee>
		<Code>2.3.9</Code>
		<name>John</name>
	</Employee>
	<Employee>
		<Code>2.3.8</Code>
		<name>John</name>
	</Employee>
	<Employee>
		<Code>11.2.4</Code>
		<name>John</name>
	</Employee>
	<Employee>
		<Code>2.3.7</Code>
		<name>John</name>
	</Employee>
	<Employee>
		<Code>d.1.5</Code>
		<name>John</name>
	</Employee>
	<Employee>
		<Code>a.2.1</Code>
		<name>John</name>
	</Employee>
	<Employee>
		<Code>c.4.2</Code>
		<name>John</name>
	</Employee>
</Employees>

split code node

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="xml"/>
	<xsl:template match="/">
		<root>
			<xsl:apply-templates select="Employees"/>
		</root>
	</xsl:template>
	<xsl:template match="Employees">
		<xsl:apply-templates select="Employee">

			<xsl:sort select="substring-before(Code,'.')" data-type="number"/>
			<xsl:sort select="substring-after(substring-before(Code,'.'),'.')" data-type="number"/>
			<xsl:sort select="substring-after(substring-after(Code,'.'),'.')" data-type="number"/>
		</xsl:apply-templates>
	</xsl:template>
	<xsl:template match="Employee">
		<Employee>
			<String1>
				<xsl:value-of select="substring-before(Code,'.')"/>
			</String1>
			<String2>
				<xsl:value-of select="substring-before(substring-after(Code,'.'),'.')"/>
			</String2>
			<String2>
				<xsl:value-of select="substring-after(substring-after(Code,'.'),'.')"/>
			</String2>
			<Code>
				<xsl:value-of select="Code"/>
			</Code>
			<Name>
				<xsl:value-of select="name"/>
			</Name>
		</Employee>
	</xsl:template>
</xsl:stylesheet>

result

<?xml version='1.0' ?>
<root>
  <Employee>
    <String1>a</String1>
    <String2>2</String2>
    <String2>1</String2>
    <Code>a.2.1</Code>
    <Name>John</Name>
  </Employee>
  <Employee>
    <String1>c</String1>
    <String2>4</String2>
    <String2>2</String2>
    <Code>c.4.2</Code>
    <Name>John</Name>
  </Employee>
  <Employee>
    <String1>d</String1>
    <String2>1</String2>
    <String2>5</String2>
    <Code>d.1.5</Code>
    <Name>John</Name>
  </Employee>
  <Employee>
    <String1>1</String1>
    <String2>2</String2>
    <String2>3</String2>
    <Code>1.2.3</Code>
    <Name>John</Name>
  </Employee>
  <Employee>
    <String1>2</String1>
    <String2>3</String2>
    <String2>7</String2>
    <Code>2.3.7</Code>
    <Name>John</Name>
  </Employee>
  <Employee>
    <String1>2</String1>
    <String2>3</String2>
    <String2>8</String2>
    <Code>2.3.8</Code>
    <Name>John</Name>
  </Employee>
  <Employee>
    <String1>2</String1>
    <String2>3</String2>
    <String2>9</String2>
    <Code>2.3.9</Code>
    <Name>John</Name>
  </Employee>
  <Employee>
    <String1>11</String1>
    <String2>2</String2>
    <String2>4</String2>
    <Code>11.2.4</Code>
    <Name>John</Name>
  </Employee>
</root>

big thx 4 the quick reply!

but the problem is i don't know the amount of tokens between the data (or there might be no tokens

it could be a.b.c and it could be a.b.c.d or only a and only b (letters only) or 1 only and 8 only, and in case of letters only or digits only this wont work any chance to compare the tokens based on its type? letters or numbers ?

thanks ahead!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.