Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xpath count using editor - NOT XSL 1

Status
Not open for further replies.

jrenae

Programmer
Jan 18, 2006
142
0
0
US
Hello,

I'm trying to get a count of nodes using xpath inside a biztalk expression editor. Please let me know if there's a better forum in which to post this.

I've tried many different approaches and I still keep getting 0. Also, I tried putting this expression in xslt to test as I've used that some before but it didn't like the syntax regarding the namespace. Is there another tool to use to test this expression against an xml file without using xslt? I've only done xpath inside of xslt and a little in querying a sql server xml datatype.

intRecordCount = System.Convert.ToInt32(xpath("count(/*[local-name()='TypedPolling' and namespace-uri()=']/*[local-name()='TypedPollingResultSet0' and namespace-uri()='])"));

intRecordCount = System.Convert.ToInt32(xpath("count(/*[local-name()='TypedPolling' and namespace-uri()=']/*[local-name()='//TypedPollingResultSet0/TypedPollingResultSet0' and namespace-uri()='])"));

intRecordCount = System.Convert.ToInt32(xpath("count(//TypedPolling/TypedPollingResultSet0/TypedPollingResultSet0 and namespace-uri()='
intRecordCount = (System.Int32)(xpath("count(/*[local-name()='TypedPolling' and namespace-uri()=']/*[local-name()='TypedPollingResultSet0' and namespace-uri()=']/*[local-name()='TypedPollingResultSet0' and namespace-uri()='])"));

intRecordCount = (System.Int32)(xpath("count(/*[local-name()='TypedPolling' and namespace-uri()=']/*[local-name()='TypedPollingResultSet0' and namespace-uri()=']/*[local-name()='TypedPollingResultSet0' and namespace-uri()='])"));

Thanks for any help!

my xml trying to get back a count of 2:

Code:
<TypedPolling xmlns="[URL unfurl="true"]http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet">[/URL]
	<TypedPollingResultSet0>
		<TypedPollingResultSet0>
			<practitionerId>10243</practitionerId>
			<ProvNum>038232</ProvNum>
			<InstitutionID>352435</InstitutionID>
			<HOSP>AAU</HOSP>
			<PractitionerAppointmentRecID>100000</PractitionerAppointmentRecID>
			<CreatedOn>2014-04-27T00:00:00Z</CreatedOn>
			<ChangedOn>2014-04-27T00:00:00Z</ChangedOn>
			<operation>2</operation>
		</TypedPollingResultSet0>
		<TypedPollingResultSet0>
			<practitionerId>10243</practitionerId>
			<ProvNum>038232</ProvNum>
			<InstitutionID>353080</InstitutionID>
			<HOSP>PCH-1</HOSP>
			<PractitionerAppointmentRecID>110533</PractitionerAppointmentRecID>
			<CreatedOn>2014-04-26T11:02:49.573Z</CreatedOn>
			<ChangedOn>2014-04-26T12:54:48.987Z</ChangedOn>
			<dateFrom>2014-04-01T00:00:00Z</dateFrom>
			<operation>2</operation>
		</TypedPollingResultSet0>
	</TypedPollingResultSet0>
</TypedPolling>
 
I am far from expert on this function in the context of BizTalk.

Do you need to be so specific that you must use namespace-uri()? Under most circumstances, local-name() would do the job. The exception is where your have elements with the same local name in different namespaces.

Clearly the third example will not work. You need to use the local-name (and namespace-uri) on each node.

Anyway, since you use XSLT to test expressions, here is an XSLT that produces the output of '2':
Code:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<xsl:output method="text"/>

<xsl:template match="/">
	<xsl:value-of select="count(/*[local-name()='TypedPolling' and namespace-uri() = '[URL unfurl="true"]http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet'[/URL] ]/*[local-name()='TypedPollingResultSet0'  and namespace-uri() = '[URL unfurl="true"]http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet'[/URL]  ]/*[local-name()='TypedPollingResultSet0' and namespace-uri() = '[URL unfurl="true"]http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet'[/URL] ])"/>
</xsl:template>

</xsl:stylesheet>

I typed it (because it was easier) without the namespace-uri() parts of the XPath predicates, and then when that worked, I added:
Code:
 and namespace-uri() = '[URL unfurl="true"]http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet'[/URL]
to each level.

Tom Morrison
Hill Country Software
 
Thank you k5tm! Yes, I was able to put that into an xslt file and it worked. I must have had a syntax error when I tried it before. I was also able to put it into the xpath evaluator in xmlspy and run it against my xml and it does work. So at least now I know the xpath is correct. It's something else inside the BizTalk editor maybe with the rest of my expression.
 
If anyone is interested in the BizTalk Editor solution I figured out that I needed to pass my message into the xpath expression as well so it new what it was evaluating... so below gave me the
record count I was looking for.

Where intRecordCount is just an int and PracApptsGetMessage is my BizTalk message that receives the sql query and pops it into the xml I referenced in the original question.

Code:
intRecordCount = (System.Int32) xpath(PracApptsGetMessage,"count(/*[local-name()='TypedPolling' and namespace-uri()='[URL unfurl="true"]http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet'[/URL]]/*[local-name()='TypedPollingResultSet0' and namespace-uri()='[URL unfurl="true"]http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet'[/URL]]/*[local-name()='TypedPollingResultSet0' and namespace-uri()='[URL unfurl="true"]http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet'[/URL]])");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top