[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Unwanted New Line on Output

Subject: RE: Unwanted New Line on Output
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 18 Jun 2007 11:13:24 +0100
RE:  Unwanted New Line on Output
It would be better to wrap the department number in its own element:

<DEPT>
    <DEPT_NR>1</DEPT_NR>
    <EMPS>
       <EMP_NAME> Fred Bloggs</EMP_NAME>
       <EMP_AGE> 25 </EMP_AGE>
   </EMPS>

or if you prefer, in an attribute:

<DEPT NR="1">
    <EMPS>
       <EMP_NAME> Fred Bloggs</EMP_NAME>
       <EMP_AGE> 25 </EMP_AGE>
   </EMPS>

I can't actually explain the output you're getting, because if the template
is invoked with DEPT as the context node, then <xsl:value-of select="DEPT"/>
will select nothing (DEPT does not have a child called DEPT), while if it is
called with DEPT_DETAILS as the context node, it will select a string such
as

\n  1  \n  \n  \Fred Bloggs \n  25  \n \n \n Joe Smith  \n  35 ....

where \n is a newline.

If you can't redesign the XML, then you can pick up the department number
(with DEPT as the context node) using normalize-space(text()[1])

Michael Kay
http://www.saxonica.com/ 
 

> -----Original Message-----
> From: Matt [mailto:puskas.duck@xxxxxxxxx] 
> Sent: 18 June 2007 10:49
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Unwanted New Line on Output
> 
> Morning list!
> 
> I have the following XML structure:
> 
> <DEPT_DETAILS>
> <DEPT>
>   1
>   <EMPS>
>      <EMP_NAME> Fred Bloggs</EMP_NAME>
>      <EMP_AGE> 25 </EMP_AGE>
>  </EMPS>
>  <EMPS>
>      <EMP_NAME> Joe Smith</EMP_NAME>
>      <EMP_AGE> 35 </EMP_AGE>
>  </EMPS>
> </DEPT>
> <DEPT>
>   2
>   <EMPS>
>      <EMP_NAME> Jill Bloggs</EMP_NAME>
>      <EMP_AGE> 19 </EMP_AGE>
>  </EMPS>
>  <EMPS>
>      <EMP_NAME> Gerry Halliwell</EMP_NAME>
>      <EMP_AGE> 45 </EMP_AGE>
>  </EMPS>
> </DEPT>
> </DEPT_DETAILS>
> 
> I want the following output (as text):
> 
> 1 Fred Bloggs
> 1 Joe Smith
> 2 Jill Bloggs
> 2 Gerry Halliwell
> 
> So my template looks something like:
> 
> <xsl:apply-template mode="depts" select="DEPT_DETAILS/DEPT"/>
> 
> <xsl:template mode="depts" match="*">
>   <xsl:param name="deptID" select="DEPT"/>
>   <xsl:for-each select="EMPS">
>      <xsl:value-of select="$deptID"/>
>      <xsl:value-of select="EMP_NAME"/>
>      <xsl:text>&#10;</xsl:text> <!-- Add CR -->
>   </xsl:for-each>
> </xsl:template>
> 
> But the output I am getting is along the lines of:
> 
> 1
>     Fred Bloggs
> 1
>     Joe Smith
> 2
>     Jill Bloggs
> 2
>    Gerry Halliwell
> 
> With the emp name being on a second line. Is this caused 
> because the dept_id is at a higher level in the XML 
> structure? Is this a problem with my select="DEPT" actually 
> selecting something more than just the ID for the department.
> 
> Any answers/suggestions appreciated....
> 
> Matt

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.