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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT problem

Status
Not open for further replies.

agentwalker

Programmer
Jun 10, 2007
31
GB
Hi,

I've got a problem when using templates where by if I apply the template to a certain node which is a child of another node it will also output the contents of all the other child nodes.

heres my xml

Code:
<myApp xmlns="[URL unfurl="true"]http://www.atestnamespace.com"[/URL] >
<data clientnnn="1234567890" datasettype="CAR">
    <datafragment trustid="123456">
      <allcareplans>
        <careplan careplanid="9242">
          <problem id="19546">
            <entrydate>2006-09-12T14:03:48</entrydate>
            <updatedate>2007-10-23T10:18:30</updatedate>
			<username>GBoon</username>
            <problemdesc>Is clinically obese, tablet controlled diabetic - oh yeah!</problemdesc>
            <problemtype>Overweight</problemtype>
            <goal id="14382">
              <description>To ensure client has a full understanding of selected diet - oh yeah!</description>
              <intervention>
                Discuss diet in full, give information leaflets
                Discuss any difficulties that the client feels they may have with the diet
              </intervention>
              <responsible>Dietition</responsible>
			  <reviewdate>2007-10-29T12:29:00.003</reviewdate>
              <interventiondesc>Diet counselling</interventiondesc>
              <updatedate>2007-10-23T10:31:04.720</updatedate>
              <entrydate>2006-09-12T14:03:48.187</entrydate>
              <username>Llens</username>
            </goal>
          </problem>
          <problem id="21037">
            <entrydate>2007-09-27T11:52:53</entrydate>
            <updatedate>2007-09-27T11:52:53</updatedate>
			<username>Bboon</username>
            <problemdesc>agafgkaf</problemdesc>
            <problemtype>Constipation</problemtype>
            <goal id="15867">
              <description>afkasdjfhjk</description>
              <intervention>hadkfhjkasd</intervention>
              <responsible>adjkhasdjkhf</responsible>
			  <reviewdate>2007-10-29T12:29:00.003</reviewdate>
              <interventiondesc>Goal setting</interventiondesc>
              <updatedate>2007-10-23T12:29:00.003</updatedate>
              <entrydate>2007-10-23T12:29:00.003</entrydate>
              <username>NLens</username>
            </goal>
            <goal id="15865">
              <description>yep</description>
              <intervention>yep</intervention>
              <responsible>yep</responsible>
			  <reviewdate>2007-10-29T12:29:00.003</reviewdate>
              <interventiondesc>Diet sheet</interventiondesc>
              <updatedate>2007-09-27T11:53:20.073</updatedate>
              <entrydate>2007-09-27T11:53:20.073</entrydate>
              <username>Nlens</username>
            </goal>
          </problem>
        </careplan>
      </allcareplans>
    </datafragment>
  </data>
</myApp>

and here's my xslt

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL]
	xmlns:do2do="[URL unfurl="true"]http://www.testnamespae.com/">[/URL]
	<xsl:output method="xml" indent="yes" />

		
	<xsl:template match="do2do:data" mode="carePlan">
		<do2do id="cpview" xmlns="[URL unfurl="true"]http://www.testnamespace.com/">[/URL]
			<xsl:apply-templates select="do2do:datafragment/do2do:allcareplans/do2do:careplan/do2do:problem"/>
		</do2do>
	</xsl:template>
	
	<!-- template for a problem -->
	<xsl:template match="do2do:problem">
		<group collapse-flagged-groups="Y" collapse-flagged-datasets="Y">
			<dataset collapse-this="Y" data-cols="2" >									
				<data label-text="Created / Modified By:"><xsl:value-of select="do2do:username" /> On <xsl:apply-templates select="do2do:updatedate"/></data>
				<date label-text="Date Entered:"><xsl:apply-templates select="do2do:entrydate"/></date>
			</dataset>
			<dataset collapse-this="N">
				<data><xsl:value-of select="do2do:problemdesc" /></data>
			</dataset>
			<dataset collapse-this="Y">
				<data label-text="Type:"><xsl:value-of select="do2do:problemtype" /></data>
			</dataset>
			<xsl:apply-templates select="do2do:goal" />
		</group>
	</xsl:template>
	
	<xsl:template match="do2do:goal">
		<group collapse-this="Y">
			<dataset>
				<row>
					<data label-text="Goal"><xsl:value-of select="do2do:description" /></data>
					<data label-text="Interventions / Actions"><xsl:value-of select="do2do:intervention" /></data>
					<data label-text="Person / Team Responsible"><xsl:value-of select="do2do:responsible" /></data>
					<data label-text="Review Date"><xsl:apply-templates match="do2do:reviewdate" /></data>
					<group collapse-this="N">
						<dataset collapse-this="N">
							<data label-text="Type:"><xsl:value-of select="do2do:interventiondesc" /></data>
						</dataset>
						<dataset collapse-this="N" data-cols="3">
							<data label-text="Entered Date:"><xsl:apply-templates match="do2do:entrydate"/></data>
							<data label-text="Update By:"><xsl:value-of select="do2do:username" /></data>
							<data label-text="Update Date:"><xsl:apply-templates match="do2do:updatedate" /></data>
						</dataset>
					</group>
				</row>
			</dataset>
		</group>
	</xsl:template>
	
		<!-- Template for a entryDate -->
	<xsl:template match="do2do:entrydate">
		<xsl:call-template name="formatISOToEnglish">						
			<xsl:with-param name="datestring" select="." />
		</xsl:call-template>	
	</xsl:template>	
	
	<!-- Templae for an UpdateDate -->
	<xsl:template match="do2do:updatedate">
		<xsl:call-template name="formatISOToEnglish">						
			<xsl:with-param name="datestring" select="." />
		</xsl:call-template>	
	</xsl:template>	
	
		<!-- Templae for an UpdateDate -->
	<xsl:template match="do2do:reviewdate">
		
		<xsl:call-template name="formatISOToEnglish">						
			<xsl:with-param name="datestring" select="." />
		</xsl:call-template>	
	</xsl:template>	
	
	
	<!-- Template to handle the conversion from the standard SQL format to a d mmm yyyy, hh:mm -->
	<xsl:template name="formatISOToEnglish">
		<xsl:param name="datestring" />
		<xsl:variable name="year"><xsl:value-of select="substring($datestring,1,4)" /></xsl:variable>
		<xsl:variable name="mnth"><xsl:value-of select="substring($datestring,6,2)" /></xsl:variable>
		<xsl:variable name="date"><xsl:value-of select="substring($datestring,9,2)" /></xsl:variable>
		<xsl:variable name="hour"><xsl:if test="string-length($datestring) &gt; 8"><xsl:value-of select="substring($datestring,9,2)" /></xsl:if></xsl:variable>
		<xsl:variable name="mnte"><xsl:if test="string-length($datestring) &gt; 8"><xsl:value-of select="substring($datestring,12,2)" /></xsl:if></xsl:variable>

		<xsl:variable name="mnthname">
			<xsl:choose>
				<xsl:when test="$mnth='01'">January</xsl:when>
				<xsl:when test="$mnth='02'">Febuary</xsl:when>
				<xsl:when test="$mnth='03'">March</xsl:when>
				<xsl:when test="$mnth='04'">April</xsl:when>
				<xsl:when test="$mnth='05'">May</xsl:when>
				<xsl:when test="$mnth='06'">June</xsl:when>
				<xsl:when test="$mnth='07'">July</xsl:when>
				<xsl:when test="$mnth='08'">August</xsl:when>
				<xsl:when test="$mnth='09'">September</xsl:when>
				<xsl:when test="$mnth='10'">October</xsl:when>
				<xsl:when test="$mnth='11'">November</xsl:when>
				<xsl:when test="$mnth='12'">December</xsl:when>
			</xsl:choose>
		</xsl:variable>
		
		<xsl:variable name="joinlot">
			<xsl:value-of select="$date" />
			<xsl:text disable-output-escaping="yes"> </xsl:text>
			<xsl:value-of select="$mnthname" />
			<xsl:text disable-output-escaping="yes"> </xsl:text>
			<xsl:value-of select="$year" />
			<xsl:if test="string-length($datestring) &gt; 8">
				<xsl:text disable-output-escaping="yes"> </xsl:text>
				<xsl:value-of select="$hour" />
				<xsl:text disable-output-escaping="yes">:</xsl:text>
				<xsl:value-of select="$mnte" />
			</xsl:if>
		</xsl:variable>
		<xsl:value-of select="$joinlot" />
	</xsl:template>
	
	

</xsl:stylesheet>

When I call the <xsl:apply-templates match="do2do:reviewdate" /> it should the <xsl:template match="do2do:reviewdate"> then run the template which formates the date and time. However whats happening is that when I call <xsl:apply-templates match="do2do:reviewdate" /> it outputs all the nodes within the "Goal" node.

Exactly the same is happening when I do the same for do2do:entrydate and do2do:updatedate within the goal node BUT when I call the same thing for the do2do:entrydate and do2do:update in the problem node it works fine.

If I extract:
<xsl:call-template name="formatISOToEnglish">
<xsl:with-param name="datestring" select="do2do:reviewdate" />
</xsl:call-template>
And call it directly from the goal template everythng works fine. Just seems to be a problem with the intemediary template i'm using to keep the code neat.


Any ideas what i'm doing wrong ????
 
Any ideas what i'm doing wrong ????

Your namespace declarations do not match:
XML document: <myApp xmlns=" >
XSLT: xmlns:do2do="
You are also relying on built-in template rules, which might not be functioning as you expect and/or giving unanticipated results.

And, finally, I don't think that the xsl:apply-templates has a match attribute. You probably want to use select.

Tom Morrison
 
Thanks was the apply-templates match="" that was the problem , switched this to select and alls fine.

I'll blame it of a friday afternoon as I started off with things fine.

ignore the namespaces i've changed them to protect the company's own namespace so slapped some random stuff in there to post here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top