Subject: Problem with formatting
Posted By: rakesh Post Date: 7/23/2008 1:05:36 PM
Hi All,

I am using XSL 1.0. I have got a requirement whose input is like this

<Players>
<player>
 <Name>Rakesh</Name>
</Player>
<player>
 <Name>Ashish</Name>
</Player>
</Players>

Now My output should be inside a column in a row

Players: Rakesh,Ashish

The problem is if i use the xsl loop and do the concatenation the output is coming like this

Players: Rakesh ,
Players:Ashish.

Can anyone help me to get correct output?

Thanks
Rakesh



Reply By: mhkay Reply Date: 7/23/2008 1:16:29 PM
Show us your code, and we can tell you where it is wrong.

(Obviously, you are outputting the string "Players" inside the loop when you should be outputting it outside the loop - but I guess you know that)

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply By: rakesh Reply Date: 7/23/2008 1:23:52 PM
Yes michael i know that. For some reason i cant output the "Players" outside the loop. I am just thinking is it possible to hold the concatenated value in a temporary variable and after concatenation output "Players" with that.

Or to be precise is it possible in xsl to have temporary variables to do manipulations. I am aware of <xsl:variable> but it more or less acts like a constant.

Any hep would be appreciated.

Thanks
Rakesh

Reply By: mhkay Reply Date: 7/23/2008 1:46:24 PM
If you show me your code then I will be able to see where you are having problems understanding the language and I can try and correct your misunderstandings. If you don't show me your code then I can't help you.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply By: rakesh Reply Date: 7/23/2008 2:06:20 PM
<xsl:for-each select="c:CourtAction">
 <tr>
   <td colspan="4">CaseNumber: <xsl:value-of select="n:CourtRecordID/i:ID"/>                                <xsl:if test="position()!=last()">,</xsl:if>
    </td>
</tr>
</xsl:for-each>

I cant put for each inside the td column because with in this loop
other rows are also being displayed similar to this

Thanks
Rakesh

Reply By: mhkay Reply Date: 7/23/2008 2:45:03 PM
Your XSLT code uses element names that aren't in your input (CourtRecord etc), and it generates elements (tr, td) that you didn't show in your desired output.

Please start again. Show us your input (with markup), your stylesheet, your actual output (with markup), and your desired output (with markup).


Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply By: rakesh Reply Date: 7/23/2008 3:12:55 PM
<Cycle >
       <CourtAction>                 
                
         <CourtCharge>
           <ChargeSequenceID >
              <ID>1</ID>
                <IDJurisdictionCode/>
            </ChargeSequenceID>
            <ChargeDescriptionText>CRIMES  </ChargeDescriptionText>
            <ChargeCountQuantity />
            <ChargeDisposition  />                   
          </CourtCharge>                 
        </CourtAction>

        <CourtAction>
      <CourtCharge>
            <ChargeSequenceID >
               <ID>2</ID>
                <IDJurisdictionCode />
             </ChargeSequenceID>
             <ChargeDescriptionText >VIOLENT </ChargeDescriptionText>
             <ChargeCountQuantity  />
             <ChargeDisposition />                    
          </CourtCharge>                
        </CourtAction>
</Cycle>

<Cycle>

  ----------
  ---------


</cycle>

Cycle can repeat 'n' times in a document


Desired output

-------------------------------------
Report                               |
-------------------------------------
Charge: CRIMES,VIOLENT               |
-------------------------------------


Actual Output


--------------------------------------
Report                                |
--------------------------------------
charge: CRIMES ,                      |
--------------------------------------
Charge: Violent                       |
--------------------------------------  

My XSL file
<xsl:for-each select="CourtAction/CourtCharge">
 <tr>
   <td colspan="4">Charge: <xsl:value-of select="ChargeDescriptionText"/>                                
     <xsl:if test="position()!=last()">,</xsl:if>
   </td>
 </tr>
</xsl:for-each>

Note: The actual output and desired output are tables

Reply By: samjudson Reply Date: 7/23/2008 4:27:25 PM
I don't see why the following doesn't work:

<tr>
  <td colspan="4">Charge:
    <xsl:for-each select="CourtAction/CourtCharge">
      <xsl:value-of select="ChargeDescriptionText"/>                                
      <xsl:if test="position()!=last()">,</xsl:if>
    </xsl:for-each>
  </td>
</tr>


/- Sam Judson : Wrox Technical Editor -/
Reply By: rakesh Reply Date: 7/23/2008 5:00:25 PM
I cant put the loop inside the <td> tag because sometimes i want to display
some other elements with in the same parent element in the same manner

for ex:

--------------------------------
Charge: Crimes,Violent| ID: 1,2|
--------------------------------

Do you have any thoughts how to do if it comes like this?

Reply By: mhkay Reply Date: 7/23/2008 5:40:27 PM
If you want to display multiple values inside one td element then of course you MUST put the loop inside the td element!

If you want to display other values in another td element then you will need another loop over the same output.

In this kind of situation your stylesheet should always follow the structure of the output, even if that means processing the input more than once.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply By: rakesh Reply Date: 7/23/2008 5:54:29 PM
Thanks Michael. Even i thought the same way. But i was just looking
if there was any better way of doing it (say use temporary variables). Anyways thanks for the help.

Rakesh


Go to topic 72951

Return to index page 1