Solved

XSL when test - need it to return zero results

Posted on 2015-02-11
3
85 Views
Last Modified: 2015-02-12
HI --

   I have this stylesheet that I'm wanting to  run a string-lengh test in.  If all of the strings are of '0' length (an empty query by a user) then I want it to return zero results.  With out this in place it will do a blank query on the DB and return all results.

Here is what I have so far

<!-- New XML document created with EditiX XML Editor (http://www.editix.com) at Wed Feb 11 14:51:56 CST 2015 -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" indent="yes"/>
	<xsl:param name="calling" select="'AE_CALLING'"/>
	<xsl:param name="called" select="'DCM4CHEE'"/>
	<xsl:param name="date" select="'20051206'"/>
	<xsl:param name="time" select="'115600.000'"/>
	<xsl:template match="/dataset">
		<dataset>
			<xsl:variable name="studyDate" select="attr[@tag='00080020']"/>
			<xsl:variable name="studyTime" select="attr[@tag='00080030']"/>
			<xsl:variable name="accNumber" select="attr[@tag='00080050']"/>
			<xsl:variable name="mod" select="attr[@tag='00080061']"/>
			<xsl:variable name="refPhy" select="attr[@tag='00080090']"/>
			<xsl:variable name="studyDesc" select="attr[@tag='00081030']"/>
			<xsl:variable name="patName" select="attr[@tag='00100010']"/>
			<xsl:variable name="patId" select="attr[@tag='00100020']"/>
			<xsl:variable name="patDOB" select="attr[@tag='00100030']"/>
			<xsl:variable name="patSex" select="attr[@tag='00100040']"/>
			<xsl:variable name="studySuid" select="attr[@tag='0020000D']"/>
			<xsl:variable name="studyId" select="attr[@tag='00200010']"/>
			<xsl:variable name="numSrs" select="attr[@tag='00201206']"/>
			<xsl:variable name="numSri" select="attr[@tag='00201208']"/>
			<xsl:variable name="studyStatid" select="attr[@tag='0032000A']"/>
			<xsl:choose>
				<xsl:when test="((string-length($studyDate)=0) and (string-length($studyTime)=0) and (string-length($accNumber)=0) and (string-length($mod)=0) and (string-length($refPhy)=0) and (string-length($studyDesc)=0) and (string-length($patName)=0) and (string-length($patId)=0) and  (string-length($patDOB)=0) and (string-length($patSex)=0) and (string-length($studySuid)=0) and (string-length($studyId)=0) and (string-length($numSrs)=0) and (string-length($numSri)=0) and (string-length($studyStatid)=0))">
					<xsl:copy-of select="attr[@tag='0020000D']"/>
				</xsl:when>
				<xsl:otherwise/>
			</xsl:choose>
		</dataset>
	</xsl:template>
</xsl:stylesheet>

Open in new window


Here is the XML:

<?xml version="1.0" encoding="UTF-8"?><dataset>
<attr tag="00080020" vr="DA" pos="0" name="Study Date" vm="0" len="0"/>
<attr tag="00080030" vr="TM" pos="8" name="Study Time" vm="0" len="0"/>
<attr tag="00080050" vr="SH" pos="16" name="Accession Number" vm="0" len="0"/>
<attr tag="00080052" vr="CS" pos="24" name="Query/Retrieve Level" vm="1" len="6">STUDY</attr>
<attr tag="00080061" vr="CS" pos="38" name="Modalities in Study" vm="0" len="0"/>
<attr tag="00080090" vr="PN" pos="46" name="Referring Physician's Name" vm="0" len="0"/>
<attr tag="00081030" vr="LO" pos="54" name="Study Description" vm="0" len="0"/>
<attr tag="00100010" vr="PN" pos="62" name="Patient's Name" vm="1" len="0"/>
<attr tag="00100020" vr="LO" pos="82" name="Patient ID" vm="0" len="0"/>
<attr tag="00100030" vr="DA" pos="90" name="Patient's Birth Date" vm="0" len="0"/>
<attr tag="00100040" vr="CS" pos="98" name="Patient's Sex" vm="0" len="0"/>
<attr tag="0020000D" vr="UI" pos="106" name="Study Instance UID" vm="0" len="0"/>
<attr tag="00200010" vr="SH" pos="114" name="Study ID" vm="0" len="0"/>
<attr tag="00201206" vr="IS" pos="122" name="Number of Study Related Series" vm="0" len="0"/>
<attr tag="00201208" vr="IS" pos="130" name="Number of Study Related Instances" vm="0" len="0"/>
<attr tag="0032000A" vr="CS" pos="138" name="Study Status ID" vm="0" len="0"/>
</dataset>

Open in new window


When I do a blank query with this in place, it will return all results.  Maybe it would be a better idea to return a $studyDate  with a value of '19000101' as this should result with no results as well.

thanks for looking
0
Comment
Question by:doc_jay
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 40604972
I am bit confused by what you want and what you have posted, but I'll have a go...

I want it to return zero results.
What do you mean by zero results? Do you mean 0 <attr> elements in the <dataset> element in the output? If so, then I think there may be a few extra things that you need to sort out (as I said, it is confusing what you are doing) but I think at least that you are needing to have the "not" keyword at the start of your string length test, eg. <xsl:when test="not ((string-length...... So that when they are NOT all zero length you include a <attr> element but when they ARE all zero length, the not inverts that to false and so the <attr> element isn't in the output.

Is this what you are after? If not, then can you try to explain further what you need to happen. Often a good way to specify what you want is to come up with a couple of different input scenarios and manually generate what you expect the output to be. Then if you can post the input and expected output for those few scenarios then we can help get you the XSLT to make it happen!
0
 

Author Comment

by:doc_jay
ID: 40606685
thanks, just the tip I needed  :)
0
 
LVL 35

Expert Comment

by:mccarl
ID: 40606799
No worries, glad to help!!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Merge XML into DOM 5 38
Load XML file into a SQL Server Table using SSIS 2012 9 57
RSS Feed Enclosure URL 1 99
Path of Workbook 3 61
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now