Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL formatting help..

Reply
Thread Tools

XSL formatting help..

 
 
icedgar
Guest
Posts: n/a
 
      03-02-2005
I currently have the following XML:

<AAA>
<dict>
<a>apple</a>
<dict>
<a>2</a>
<dict>
<a>James</a>
<x>1</x>
<a>Tammy</a>
<y>2</y>
<a>Pat</a>
<z>3</z>
<a>George</a>
<z>4</z>
<a>Fred</a>
<x>5</x>
</dict>
<a>4</a>
<dict>
<a>James</a>
<x>1</x>
<a>Tammy</a>
<y>2</y>
<a>Pat</a>
<z>3</z>
<a>George</a>
<z>4</z>
<a>Fred</a>
<z>5</z>
</dict>
</dict>
</dict>
</AAA>

When I apply the following XSL template:

<xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0"> <xslutput method="xml"/>
<xslutput indent="yes"/>


<xsl:template match="/AAA/dict/dict/*">
<xsl:copy>
<xsl:apply-templates select="a"/>
</xsl:copy>
</xsl:template>


<xsl:template match="a">
<xsl:attribute name="{translate(.,' ','_')}">
<xsl:apply-templates select="following-sibling::*[1]"/>

</xsl:attribute>
</xsl:template>
</xsl:stylesheet>

I get the following results:
<a></a>
<dict James="1" Tammy="2" Pat="3" George="4" Fred="5"></dict>
<a></a>
<dict James="1" Tammy="2" Pat="3" George="4" Fred="5"></dict>

Which is what I want but in a different format. I need the following
output to look like this below:

<labels>
James="1"
Tammy="2"
Pat="3"
George="4"
Fred="5"
</labels>
<labels>
James="1"
Tammy="2"
Pat="3"
George="4"
Fred="5"
</labels>


I am still a newbie at this. Any help would be great.

Thanks in advance.

 
Reply With Quote
 
 
 
 
grghoward@no.spam.email.com.no.spam
Guest
Posts: n/a
 
      03-03-2005
I'm still somewhat new to this myself, but I just ran this version of
the stylesheet through Xalan and got your desired results:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput method="xml"/>
<xslutput indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates select="AAA/dict/dict/*"/>
</xsl:template>

<xsl:template match="AAA/dict/dict/*">
<xsl:if test="a">
<xsl:text> </xsl:text>
<labels>
<xsl:text> </xsl:text>
<xsl:apply-templates select="a"/>
<xsl:text> </xsl:text>
</labels>
</xsl:if>
</xsl:template>

<xsl:template match="a">
<xsl:text> </xsl:text>
<xsl:value-of select="." />
<xsl:text>="</xsl:text>
<xsl:value-of select="following-sibling::*[1]" />
<xsl:text>" </xsl:text>
</xsl:template>

</xsl:stylesheet>

I believe if you try it you will get what you wanted.

-Greg

 
Reply With Quote
 
 
 
 
icedgar
Guest
Posts: n/a
 
      03-03-2005
Thanks Greg.. that worked great!! Much appreciated. I was having a
hell of a time using the <xsl:text> flag. It kept moving all the data
around. This will help me with my formatting in the future too.
Thanks again.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
Need Help Converting formatting tags embedded in entities to XSL:FO instructions slberry XML 0 05-15-2004 01:48 AM
XSL Date formatting Suvig XML 1 04-02-2004 11:28 AM
XSL-FO - Formatting single line with different text-alignments Lorentz XML 4 02-27-2004 03:13 PM
Need formatting options menu for formatting hard drive Mark T. Computer Support 3 11-24-2003 11:50 PM



Advertisments