XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Cardician LegerdemainSubject: Display two values on one line?
Author: Cardician Legerdemain
Date: 03 Jun 2005 10:19 AM
Hello,

I've looked high and low and can't seem to find an example of what I'm trying to do. Here is my basic XML:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE DOC SYSTEM "/dtd/example.dtd">
<DOC>
<METADATA>
<BOOKS>
<US-BOOKS>
<INFO>
<CONTROLSYSTEM CONTROL="Blah"></CONTROLSYSTEM>
<CONTROLSYSTEM CONTROL="Xyz"></CONTROLSYSTEM>
</INFO>
</US-BOOKS>
</BOOKS>
</METADATA>
</DOC>

What I want to do, is while pulling values out with XSLT, put the two Control values on one line seperated by a comma. So the output would be:

Info: Blah, Xyz

Here is what I've tried so far:

<xsl:template match="DOC">
<xsl:for-each select="METADATA/BOOKS/US-BOOKS/INFO">
Info: <xsl:value-of select="@CONTROL"/>, <xsl:text/>
</xsl:for-each>
</xsl:template>

This will print the Info: part and a comma, but does not print any values. Can anyone offer any insight? This seems like it would be simple to do yet no matter what combinations of things I try I cannot get it to display propery, or at all. Thank you.

Postnext
Ivan PedruzziSubject: Display two values on one line?
Author: Ivan Pedruzzi
Date: 03 Jun 2005 10:43 AM

The following should do

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:template match="/">

<xsl:for-each select="DOC/METADATA/BOOKS/US-BOOKS/INFO">
<xsl:value-of select="concat('Info: ',
CONTROLSYSTEM[1]/@CONTROL, ', ' ,
CONTROLSYSTEM[2]/@CONTROL)"/><xsl:text>
</xsl:text>
</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

Postnext
Cardician LegerdemainSubject: Display two values on one line?
Author: Cardician Legerdemain
Date: 03 Jun 2005 11:27 AM
Originally Posted: 03 Jun 2005 10:49 AM
Fantastic! However, I forgot to mention one other (rather important) point. While that will work great, I can't always be sure that there will only be two CONTROLSYSTEM tags. Is there any way to make the code just get and concatenate however many there happen to be? There could only be one, or there could be three or more.<br> <br> Thank you though, that was helpful in pointing me closer to the answer I'm looking for.

Postnext
Ivan PedruzziSubject: Display two values on one line?
Author: Ivan Pedruzzi
Date: 03 Jun 2005 11:02 AM

<xsl:template match="/">
<xsl:for-each select="DOC/METADATA/BOOKS/US-BOOKS/INFO">
<xsl:text>Info: </xsl:text>
<xsl:for-each select="CONTROLSYSTEM/@CONTROL">
<xsl:if test="position() &gt; 1"><xsl:text>, </xsl:text></xsl:if>
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:for-each>

</xsl:template>

Posttop
Cardician LegerdemainSubject: Display two values on one line?
Author: Cardician Legerdemain
Date: 06 Jun 2005 09:07 AM
That works beautifully. Thank you so much for the help.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.