 |
| 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
|
|
|
|

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

July 23rd, 2008, 01:16 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

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

July 23rd, 2008, 01:46 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

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

July 23rd, 2008, 02:45 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

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

July 23rd, 2008, 04:27 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

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

July 23rd, 2008, 05:40 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|
 |