473,396 Members | 2,013 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,396 software developers and data experts.

Like sibling processing template(s) needed

Hello,

I have a situation where I need to group an arbitrary number of like sibling
input elements into a compound output element as follows:

Input:
<feature>
Jul 20 '05 #1
5 1609
Mike Conmackie (Thu, 29 Apr 2004 14:06:11 -0400):

Input:
<feature>
.
.
<hostid type="ethernet">0004d355b321</hostid>
<hostid type="ethernet">000123456789</hostid>
<nostid type="ethernet">000987654321</hostid>
.
.
</feature>

Output:
<key>
.
.
<hostid>
<Eth>0004d355b321</Eth>
<Eth>000123456789</Eth>
<Eth>000987654321</Eth>
</hostid>
.
.
</key>


<xsl:template>
<xsl:if test="//hostid[@type='ethernet']">
<hostid>
<xsl:for-each select="//hostid[@type='ethernet']">
<Eth><xsl:value-of select="."/></Eth>
</xsl:for-each>
</hostid>
</xsl:if>
</xsl:template>

I think this solution lacks some elegance, but I think it will work.
Chris
--
Chris Huebsch www.hübsch-gemacht.de | TU Chemmnitz, Informatik, RNVS
GPG-Encrypted mail welcome! ID:7F2B4DBA | Str. d. Nationen 62, B204
Chemnitzer Linux-Tage 2005, 5.-6.März | D-09107 Chemnitz
http://www.tu-chemnitz.de/linux/tag/ | +49 371 531-1377, Fax -1803
Jul 20 '05 #2

"Chris Huebsch" <ch***********@informatik.tu-chemnitz.de> wrote in message
news:sl**************************@chu.informatik.t u-chemnitz.de...
Mike Conmackie (Thu, 29 Apr 2004 14:06:11 -0400):

Input:
<feature>
.
.
<hostid type="ethernet">0004d355b321</hostid>
<hostid type="ethernet">000123456789</hostid>
<nostid type="ethernet">000987654321</hostid>
.
.
</feature>

Output:
<key>
.
.
<hostid>
<Eth>0004d355b321</Eth>
<Eth>000123456789</Eth>
<Eth>000987654321</Eth>
</hostid>
.
.
</key>


<xsl:template>
<xsl:if test="//hostid[@type='ethernet']">
<hostid>
<xsl:for-each select="//hostid[@type='ethernet']">
<Eth><xsl:value-of select="."/></Eth>
</xsl:for-each>
</hostid>
</xsl:if>
</xsl:template>

I think this solution lacks some elegance, but I think it will work.
Chris
--
Chris Huebsch www.hübsch-gemacht.de | TU Chemmnitz, Informatik, RNVS
GPG-Encrypted mail welcome! ID:7F2B4DBA | Str. d. Nationen 62, B204
Chemnitzer Linux-Tage 2005, 5.-6.März | D-09107 Chemnitz
http://www.tu-chemnitz.de/linux/tag/ | +49 371 531-1377, Fax -1803


Chris,

I may have lead you astray with a rather simple example. In actuality, the
input could look like this:

<feature>
Jul 20 '05 #3
Mike Conmackie (Thu, 29 Apr 2004 14:42:28 -0400):
I may have lead you astray with a rather simple example. In actuality, the
input could look like this:
Yes you did :-)
<feature>
.
.
<hostid type="ethernet">0004d355b321</hostid>
<hostid type="internet">127.0.0.1</hostid>
<hostid type="serial">1DFFF375281007509B</hostid>
<hostid type="softkey">D12C7143E283D2E</hostid>
.
.
</feature> I thought that if I could get an XPath expression that would create a node
set comprised of similar siblings at a given input tree location then I
could iterate over the set. Does this sound reasonable?
It does.

But let me ask - can you send some more lines of your xml-document?
Perhaps an other host?

Does it look like this:

<hostid type="ethernet">000abacde321</hostid>
<hostid type="internet">127.0.0.2</hostid>
<hostid type="serial">1DFFF3ddd3334555gB</hostid>
<hostid type="softkey">111122223333444</hostid>
<hostid type="ethernet">0004d355b321</hostid>
<hostid type="internet">127.0.0.1</hostid>
<hostid type="serial">1DFFF375281007509B</hostid>
<hostid type="softkey">D12C7143E283D2E</hostid>


If the answer is yes - are there allways those 4 hostid-elements?
Chris
--
Chris Huebsch www.hübsch-gemacht.de | TU Chemmnitz, Informatik, RNVS
GPG-Encrypted mail welcome! ID:7F2B4DBA | Str. d. Nationen 62, B204
Chemnitzer Linux-Tage 2005, 5.-6.März | D-09107 Chemnitz
http://www.tu-chemnitz.de/linux/tag/ | +49 371 531-1377, Fax -1803
Jul 20 '05 #4
Hi Chris,
But let me ask - can you send some more lines of your xml-document?
Perhaps an other host?
I e-mailed you a sample XML input document.
Does it look like this:

<hostid type="ethernet">000abacde321</hostid>
<hostid type="internet">127.0.0.2</hostid>
<hostid type="serial">1DFFF3ddd3334555gB</hostid>
<hostid type="softkey">111122223333444</hostid>
<hostid type="ethernet">0004d355b321</hostid>
<hostid type="internet">127.0.0.1</hostid>
<hostid type="serial">1DFFF375281007509B</hostid>
<hostid type="softkey">D12C7143E283D2E</hostid>


If the answer is yes - are there allways those 4 hostid-elements?


Yes, it could look like that. There can be from 1 to n <hostid> tags and
the value of the "type" attribute can be any one of a fixed set of 4 values
{ethernet, serial, softkey, internet}. Hope this helps.

Mike

Jul 20 '05 #5
Mike Conmackie (Thu, 29 Apr 2004 19:11:21 -0400):
Yes, it could look like that. There can be from 1 to n <hostid> tags and
the value of the "type" attribute can be any one of a fixed set of 4 values
{ethernet, serial, softkey, internet}. Hope this helps.


Ok. I tried the following templates:

<xsl:template match="feature">
<xsl:element name="key">
<xsl:attribute name="protected" />
<xsl:apply-templates select="name|version|start|expires|count"/>
<xsl:call-template name="hostids"/>
</xsl:element>
</xsl:template>

<xsl:template name="hostids">
<xsl:if test="hostid[@type='ethernet']">
<hostid>
<xsl:apply-templates select="hostid[@type='ethernet']">
<xsl:with-param name="element">Eth</xsl:with-param>
</xsl:apply-templates>
</hostid>
</xsl:if>
<xsl:if test="hostid[@type='serial']">
<hostid>
<xsl:apply-templates select="hostid[@type='serial']">
<xsl:with-param name="element">Serial</xsl:with-param>
</xsl:apply-templates>
</hostid>
</xsl:if>
<xsl:if test="hostid[@type='softkey']">
<hostid>
<xsl:apply-templates select="hostid[@type='softkey']">
<xsl:with-param name="element">Softkey_id</xsl:with-param>
</xsl:apply-templates>
</hostid>
</xsl:if>
</xsl:template>

<xsl:template match="hostid">
<xsl:param name="element"/>
<xsl:element name="{$element}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
Its not really nice. Esp. the 3 rather similar if-s.
Regards
Chris
PS: I'll mail you the complete template back.
--
Chris Huebsch www.hübsch-gemacht.de | TU Chemmnitz, Informatik, RNVS
GPG-Encrypted mail welcome! ID:7F2B4DBA | Str. d. Nationen 62, B204
Chemnitzer Linux-Tage 2005, 5.-6.März | D-09107 Chemnitz
http://www.tu-chemnitz.de/linux/tag/ | +49 371 531-1377, Fax -1803
Jul 20 '05 #6

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

Similar topics

9
by: Sebastian Faust | last post by:
Hi, I have a design problem about which I am thinking now for a while and still couldnt find any help in deja. What I need is something like a virtual function template. I know that this is not...
1
by: bjam | last post by:
Hi, if I want to include a set of call template methods into my xsl file can I do that? Meaning I want to have the template method below of data_output in another file that I can use in several...
2
by: Jim West | last post by:
I have a template class (for numerical processing) that was originally written for real data that I need to extend to complex data, and I am running into a problem. The current version (greatly...
2
by: Frank Schmitt | last post by:
Hi! Suppose I have a class template Foo with a member function template bar - so far so good: template <typename T> struct Foo { template <typename U> void bar(const U& u); };
6
by: NKOBAYE027 | last post by:
FIRST POST Hi All: I'm trying to write a simple specialization before moving on to something a bit more complex - always a good idea in my case, at least. :o) I'm trying to adapt the example...
2
by: Xenos | last post by:
The new version of GCC is out and in its list of changes, it talks about the C++ Standard's requirements for using the typename and template keywords to disambiguate dependent names. I'm use to...
13
by: Walt Karas | last post by:
The following gives an error in the declaration of the member function x() of the class template Tpl, compiliing with a recent version of GCC under Solaris: class A { }; class B { }; ...
2
by: Yang Zhang | last post by:
I have a small program like this: //////////////////////////////////////////////// #include <iostream> using namespace std ; // set bits in an address template <typename T> inline T*...
0
by: resurgentnaveen | last post by:
Hi , I am trying to use Active Scaffold in my project and i need this template overriding feature of Active Scaffold. I am following the instructions on the link...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.