473,804 Members | 3,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1633
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>0004d355b3 21</Eth>
<Eth>0001234567 89</Eth>
<Eth>0009876543 21</Eth>
</hostid>
.
.
</key>


<xsl:template >
<xsl:if test="//hostid[@type='ethernet ']">
<hostid>
<xsl:for-each select="//hostid[@type='ethernet ']">
<Eth><xsl:val ue-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.informa tik.tu-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>0004d355b3 21</Eth>
<Eth>0001234567 89</Eth>
<Eth>0009876543 21</Eth>
</hostid>
.
.
</key>


<xsl:template >
<xsl:if test="//hostid[@type='ethernet ']">
<hostid>
<xsl:for-each select="//hostid[@type='ethernet ']">
<Eth><xsl:val ue-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">1 DFFF37528100750 9B</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">1 DFFF3ddd3334555 gB</hostid>
<hostid type="softkey"> 111122223333444 </hostid>
<hostid type="ethernet" >0004d355b321 </hostid>
<hostid type="internet" >127.0.0.1</hostid>
<hostid type="serial">1 DFFF37528100750 9B</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">1 DFFF3ddd3334555 gB</hostid>
<hostid type="softkey"> 111122223333444 </hostid>
<hostid type="ethernet" >0004d355b321 </hostid>
<hostid type="internet" >127.0.0.1</hostid>
<hostid type="serial">1 DFFF37528100750 9B</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:attribut e name="protected " />
<xsl:apply-templates select="name|ve rsion|start|exp ires|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
10286
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 possible, so I need "something like" a virtual function template. I read in some threads that there is a workaround using the visitor pattern. I read therefore in the book "Modern c++ Design" about this pattern, but couldnt find any help to my...
1
1585
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 other xsl files when needed. This would be similar to an inclue mindset in C++ or a import in java. Any help is greatly appreciated. Below I would like the "data_output" template call to be imported so to speak or come from another xsl file,...
2
1657
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 simplified) has something like template <class T> class FOO { T A; T B; };
2
2491
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
1776
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 from Stroustrup, 3rd ed., The C++ Programming Language p. 344 I'm using MSDev 6.0 in case that's an issue. Here's the source...
2
7953
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 seeing typename being used, but I've never seen template used for this purpose. I've studied there example for a long time, and still don't understand what situations call for the template keyword (and reading the standard, to me, is Greek). Can...
13
2831
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 { }; template <typename Base> class Tpl : protected Base {
2
1780
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* set_addr(const T* addr, unsigned long n) {
0
1963
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 http://www.activescaffold.com/docs/template-overrides Could someone help me some piece of code for that Thanks in Advance
0
9704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9569
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9130
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2975
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.