INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

xpath count using editor - NOT XSL

xpath count using editor - NOT XSL

(OP)
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()='http://schemas.microsoft.com/Sql/2008/05/TypedPoll...']/*[local-name()='TypedPollingResultSet0' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedPoll...'])"));

intRecordCount = System.Convert.ToInt32(xpath("count(/*[local-name()='TypedPolling' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedPoll...']/*[local-name()='//TypedPollingResultSet0/TypedPollingResultSet0' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedPoll...'])"));

intRecordCount = System.Convert.ToInt32(xpath("count(//TypedPolling/TypedPollingResultSet0/TypedPollingResultSet0 and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedPoll...')"));

intRecordCount = (System.Int32)(xpath("count(/*[local-name()='TypedPolling' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedPoll...']/*[local-name()='TypedPollingResultSet0' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedPoll...']/*[local-name()='TypedPollingResultSet0' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedPoll...'])"));

intRecordCount = (System.Int32)(xpath("count(/*[local-name()='TypedPolling' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedPoll...']/*[local-name()='TypedPollingResultSet0' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedPoll...']/*[local-name()='TypedPollingResultSet0' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedPoll...'])"));

Thanks for any help!

my xml trying to get back a count of 2:

CODE

<TypedPolling xmlns="http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet">
	<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> 

RE: xpath count using editor - NOT XSL

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 --> XSLT

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

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

and namespace-uri() = 'http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet' 
to each level.

Tom Morrison
Hill Country Software

RE: xpath count using editor - NOT XSL

(OP)
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.

RE: xpath count using editor - NOT XSL

(OP)
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()='http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet']/*[local-name()='TypedPollingResultSet0' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet']/*[local-name()='TypedPollingResultSet0' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedPolling/PracApptsGet'])"); 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close