473,385 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

XSL: question on using general * templates

I need help with using a general template which would process all tags
other than the ones for which specific templates have been written.

My XML looks like this:

<ITEMS>
<SPECIAL1>abc</SPECIAL1>
<SPECIAL2>abc</SPECIAL2>
...
<SPECIAL12>abc</SPECIAL9>
...
<KEY>0</KEY>
<KEY>1</KEY>
...
<OTHER1>xyz</OTHER1>
<OTHER2>xyz</OTHER2>
...
</ITEMS>
--------------------------------------

I need to convert to this format:

<elements>
//all SPECIAL tags are processed with a template correctly
<keys>
// all KEY tags processed with a template correctly
<keys>
//all tags other than the above mentioned need to be converted like
this.
<features>
<feature>
<name>other1</name>
<value>xyz</value>
</feature>
</feature>
<name>other2</name>
<value>xyz</value>
</feature>
</features>
</elements>
--------------------------------------

My xsl looks like this:

<xsl:template match="ITEMS">
<elements>
<xsl:apply-templates select="SPECIAL1" />
<xsl:apply-templates select="SPECIAL2" />
...
...
<xsl:if test="count(KEY) &gt; 0">
<keys>
<xsl:apply-templates select="KEY" />
</keys>
</xsl:if>

//WORKS FINE TILL THIS POINT

<features>
<xsl:apply-templates/>
</features>
</elements>
</xsl:template>

//TEMPLATES FOR SPECIAL1, SPECIAL2, KEY etc defined here

//general template definition
<xsl:template match="*">
<xsl:variable name="tag_value">
<xsl:value-of select="."/>
</xsl:variable>
<feature>
<name><xsl:value-of select="name(.)"/></name>
<value><xsl:value-of select="$tag_value"/></value>
</feature>
</xsl:template>

--------------------------------------

But this general template doesn't work. It gets invoked for all tags
regardless of the fact that they have their own templates defined.

I really need to figure out when I get a tag that is NOT SPECIAL1,
SPECIAL2...KEY then dump all those tags into a
<features></features> root tag in the new format.

How can I get the above behaviour?

Thanks for any help.
Rohit.

Dec 27 '05 #1
0 1293

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Simon Harvey | last post by:
Hi everyone, I am fairly new to learning about xsl and xml, but one thing I have noticed is that anyone offering a tutorial or lesson on it seems to think that its the most incredible invention...
2
by: Adelard | last post by:
Here is my xsl and xml, I want the xml node: LABEL3 ( General Information ) to move under the ROW when viewing or printing this PDF Document. How can I do it? Thanks
0
by: Sharon | last post by:
Hiya, I have this stylesheet (based on an example @ http://rdcpro.com/xmldev/filterandsort)which I'm trying to modify so that it will work for my own XML and I get some data but it doesn't appear...
7
by: Sharon | last post by:
Hi, Is it possible to check parameters against other parameters, as in: <xsl:variable name="tableData"> <xsl:apply-templates select="general/data/rows/row/fvalues" mode="tableData" />...
4
by: Pat Turner | last post by:
Hi, I have some XML like this: <family> <person name="bob"> <father ref="../../person" /> </person> <person name="charlie"> <child ref="../../person" />
3
by: william_hulse | last post by:
The general process i am currently working on is this: STEP 1 xml doc1 is transformed using stylesheet1 to produce xml doc2 - xml doc1 has a namespace declaration as follows... <?xml...
4
by: JLP | last post by:
Hello, I have a couple of hundred books in TEI based XML. I want to output html and pdf documents. I started building my own style sheets to do this and I ran into a problem with footnotes. Many...
3
by: Steve | last post by:
Is there any way of specifying the startMode when using the xslTransform class? We are updating code which used msxml to the system.xml classes but can find no way to specify the startMode. We...
4
by: Piper707 | last post by:
I need help with using a general template which would process all tags other than the ones for which specific templates have been written. My XML looks like this: <ITEMS>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.