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 August 31st, 2004, 10:59 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default select wildcard element names

I want to apply a single template to a number of elements with similar names, but somewhat different.

the elements all begin with ELE

so, can I do:
<xsl:apply-templates select="ELE*"/>

<xsl:template match="ELE*">
 <xsl:value-of select="."/>
</xsl:template>

? what is a way to do this?

thanks,
-L

 
Old August 31st, 2004, 11:13 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You can do
Code:
<xsl:apply-templates select="*[starts-with(name(), 'ELE')]"/>


--

Joe (Co-author Beginning XML, 3rd edition)
 
Old August 31st, 2004, 11:21 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

cool, thanks. one other question...now I have...

Code:
<xsl:template match="*[starts-with(name(), 'SEG'))]">
    <xsl:value-of select="name"/>*<xsl:apply-templates select="*[starts-with(name(), 'ELE')]"/>
</xsl:template>

<xsl:template match="*[starts-with(name(), 'ELE')]">
    <xsl:value-of select="."/>*
</xsl:template>
I want the final document to be a flat-file (EDI) looking like this:
BPR*<ELE data here>*<next ELE data here>*<carraige return>
N1*<ELE data here>*<next ELE data here>*<carraige return>

my question is how do I put in carriage returns in the result document...I know there's some XSLT function or something, but if you know what it is off the top of your head it could save me some digging...thanks,

-L

 
Old September 1st, 2004, 02:14 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Carriage returns are characters 13, new line is 10 I usually use hex notation:
Code:
#0a;#0d;
Not sure how these will fare in abrowser but they are:
ampersand hash zero a semi-colon
ampersand hash zero d semi-colon

I think your stylesheet should be more like:
Code:
<xsl:template match="*[starts-with(name(), 'SEG'))]">
    <xsl:value-of select="name()"/>
<xsl:value-of select=".>
<xsl:apply-templates select="*[starts-with(name(), 'ELE')]"/>
</xsl:template>

<xsl:template match="*[starts-with(name(), 'ELE')]">
    <xsl:value-of select="."/>
</xsl:template>
--

Joe (Co-author Beginning XML, 3rd edition)
 
Old September 1st, 2004, 08:12 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
<xsl:template match="*[starts-with(name(), 'SEG')]">
<xsl:value-of select="NAME"/><xsl:text>*</xsl:text><xsl:apply-templates select="*[starts-with(name(), 'ELE')]"/>
</xsl:template>
<xsl:template match="*[starts-with(name(), 'ELE')]">
<xsl:value-of select="."/><xsl:text>*</xsl:text>
</xsl:template>
is the template code I'm using now, and a sample XML:

Code:
<SEG>
<NAME>BPR</NAME>
<ELE1>100285</ELE1>
<ELE2>IV</ELE2>
<ELE3>123.45</ELE3>
<ELE4/>
<ELE5/>
</SEG>
<SEG>
<NAME>RMR</NAME>
<ELE1>IV</ELE1>
</SEG>
Seems to be working fine now. Thanks for all the help!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Element Names - Dashes Suu XML 3 August 2nd, 2007 08:49 AM
Select all Database Names bekim SQL Server 2000 1 March 20th, 2006 03:43 PM
Getting form element names in a loop crapanz Javascript 5 January 30th, 2006 12:45 AM
XSL select by child element value vivhost XSLT 3 May 21st, 2005 02:58 AM
Duplicate Element Names carolynk XML 1 September 30th, 2004 09:22 AM





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