954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Getting XML output count and input record position using xslt 1.0

Hi Guys,

I am new to XSLT, looking to solve a problem I am facing in filtering XML records.

I need to get both the Input XML record position and limit the output XML to a particular number (based on input provided to xsl:param from .net 1.1)

Input XML
AAAABADAADBAABZAOutput XML(Required)

DAA

I am using XSLT:starts-with to get the records I need. But I am only able to limit the count or record position at any one point of time using the position() method.

Can anyone tell me how to achieve this,

Thanks,
Sarath

sarathcd
Newbie Poster
1 post since Apr 2011
Reputation Points: 10
Solved Threads: 0
 

I use param to the outside to control xslt

The first parameter indicates the length of a string
The second parameter is the string being searched

by specifying

and not (preceding-sibling:: Child [substring (.,1,$length) = $alpha]

only the first matching child node appears

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="html"/>
	<xsl:param name="length" select="1"/>
	<xsl:param name="alpha" select="'B'"/>
	<xsl:template match="/">
		<html>
			<body>
				<xsl:apply-templates select="Parent"/>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="Parent">
		<table>
			<xsl:apply-templates select="Child"/>
		</table>
	</xsl:template>

	<xsl:template match="Child">
		<xsl:if test="(substring(.,1,$length) = $alpha) and not(preceding-sibling::Child[substring(.,1,$length) = $alpha])">
			<tr>
				<td id="Row{position()}">
					<xsl:value-of select="."/>
				</td>
			</tr>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>


result param1=1 param2='B'

<html>
  <body>
    <table>
      <tr>
        <td id="Row5">BZA</td>
      </tr>
    </table>
  </body>
</html>
xml_looser
Junior Poster
179 posts since Apr 2009
Reputation Points: 16
Solved Threads: 21
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: