Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 23rd, 2008, 01:05 PM
Authorized User
 
Join Date: Jul 2008
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with formatting

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



 
Old July 23rd, 2008, 01:16 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old July 23rd, 2008, 01:23 PM
Authorized User
 
Join Date: Jul 2008
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old July 23rd, 2008, 01:46 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old July 23rd, 2008, 02:06 PM
Authorized User
 
Join Date: Jul 2008
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<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

 
Old July 23rd, 2008, 02:45 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old July 23rd, 2008, 03:12 PM
Authorized User
 
Join Date: Jul 2008
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<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

 
Old July 23rd, 2008, 04:27 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
 
Old July 23rd, 2008, 05:00 PM
Authorized User
 
Join Date: Jul 2008
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

 
Old July 23rd, 2008, 05:40 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Css formatting problem beetle_jaipur CSS Cascading Style Sheets 2 June 5th, 2009 07:16 AM
Formatting Problem hewstone999 Access VBA 3 March 11th, 2008 07:17 AM
formatting problem everest ASP.NET 1.0 and 1.1 Professional 2 October 5th, 2005 09:59 AM
General formatting problem...... mike_remember ASP.NET 1.x and 2.0 Application Design 1 October 5th, 2004 09:18 AM
Query/formatting problem in report mega Access VBA 8 September 16th, 2004 04:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.