Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

XSL when test - need it to return zero results

Posted on 2015-02-11
3
87 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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