DaciaClub Logo

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topicStart Poll

Outline · [ Standard ] · Linear+

> XML : cum pot sa caut in denumirea, unui atribut?

GeorgeB
post 13 Dec 2004, 12:20
Post #1


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




intrebare de baraj.

am un atribut id cu o valoare valoare.

eu vreau sa pot sa caut dupa atribut value asa : 'atribute%2'

adica sa-mi returneze toate elementele care incep cu atribute si se termina cu 2.

cum fac asta in XSL ? blink.gif


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
MoneyTalks
post 13 Dec 2004, 12:21
Post #2


-


Group: Members
Posts: 2.712
Joined: 18 April 03
From: Ireland




Ce folosesti pentru analiza codului?


--------------------
Lexus ES300H 2020
Religia a aparut cind primul ticalos s-a intilnit cu primul prost

Never underestimate the power of stupidity in large groups
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 12:24
Post #3


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




codul il prelucrez in visual . net

am o pagina XML care o transform cu un XSLT. problemea mea este ca am niste itemuri recursive pe acolo laugh.gif si singura posibilitate pe care o vad eu de a parcure acest XML este sa fac o "sortare" dupa id. dar imi trebuie musai, pentru a face sortarea, sa stiu cum pot sa ii spun : adu-mi toate elementele ale calor atribut id este incepe cu 'xxx%' , unde procent = orice.

am ceva de genul:
<doc>
<item/>
</doc>

unde item :
<item>
<h></h>
<b></b>
<item></item>
</item>

rolleyes.gif


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
MoneyTalks
post 13 Dec 2004, 12:25
Post #4


-


Group: Members
Posts: 2.712
Joined: 18 April 03
From: Ireland




La acea parcurgere recursiva ai un case care iti rezolva problema.


--------------------
Lexus ES300H 2020
Religia a aparut cind primul ticalos s-a intilnit cu primul prost

Never underestimate the power of stupidity in large groups
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 12:27
Post #5


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




exemplu te rog happy.gif


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
MoneyTalks
post 13 Dec 2004, 12:33
Post #6


-


Group: Members
Posts: 2.712
Joined: 18 April 03
From: Ireland




Folosesti o functie numita startelement? In acea functie analizezi ce te intereseaza.


--------------------
Lexus ES300H 2020
Religia a aparut cind primul ticalos s-a intilnit cu primul prost

Never underestimate the power of stupidity in large groups
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 12:38
Post #7


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




am gasit asta happy.gif
CODE

//region[starts-with(@name, 'S')]
----------------------------------------
sau
----------------------------------------
//region[contains(@name, 'east')]


din msdn : Processing Text Strings by Using String Functions


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
MoneyTalks
post 13 Dec 2004, 12:43
Post #8


-


Group: Members
Posts: 2.712
Joined: 18 April 03
From: Ireland




In principiu ai 3 functii:

startElement: cind incepe un element
endElement: cind se termina un element
charData: cind analizezi continutul (valoarea) atributului

Fiecare din aceste functii are un case, care analizeaza elementele pe care le poti avea in fisierul analizat (deci le faci particulare la ceea ce ai nevoie)

In aceste functii scrii codul de care ai nevoie. Denumirile functiilor poate diferi, dar in esenta fac acelasi lucru


--------------------
Lexus ES300H 2020
Religia a aparut cind primul ticalos s-a intilnit cu primul prost

Never underestimate the power of stupidity in large groups
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 12:50
Post #9


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




daaaaaaaaaaa , multumesc. testez acum sa vad dc functioneaza biggrin.gif

acum pb este cum parcurge xml ul ? pe fiecare nivel SAU pe fiecare nivel pana la element final si pe urma ia urmatorul element de pe nivel .

adica :
(1)
(11)
(12)
...
(2)
(3)

sau

(1)
(2)
(3)
(11)
(12)
....



--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 12:55
Post #10


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




hmmmm...

la mine id urile ITEM urilor sunt de genul :
do
do|ca1
do|ca1|se1
do|ca2
do|ca2|se1
do|ca2|se2

cum pot sa-i spun : adu-mi toate elementele care sunt sectiuni (se) ?

oricum am mai avansat , multumesc wub.gif

never mind . biggrin.gif ca am gasit laugh.gif


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 13:11
Post #11


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




ei bine :

daca ii dau sa-mi aduca toate elementele (nodurile) care au in componenta 'ca' atunci imi aduce : '%ca%|se|...' adica imi aduce tot ce se gaseste pe acea ramura dupa ce a gasit un element ce contine 'ca'



--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 13:21
Post #12


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




cum ii pot spune : bre, afiseaza-mi doar valoare respectivului element nu si fii lui ...


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 14:31
Post #13


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




rezolvarea:
pentru a parcurge un fisier XML iregular, care contine elemente recursive(conform MSDN Irregular Data Hierarchies) :
se folosesc template uri :


Example of Transforming Irregular Data Hierarchies
This example illustrates the data-driven model of XSLT processing. With the data-driven model, you can create isolated templates for the types of nodes you expect to see in the output, without too much consideration of their structure. In places where the structure is locally known, you can use <xsl:for-each> and <xsl:value-of> to populate the template. For example, <list> and <item> elements appear in a regular and predictable structure. The capacity to switch smoothly between data-driven and template-driven transformation is an important feature of XSLT.

XML File (pole.xml)

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="poleeasy.xsl"?>
<document>
<title>To the Pole and Back</title>
<section>
<title>The First Day</title>
<p>It was the <emph>best</emph> of days, it was the
<emph>worst</emph> of days.</p>
<list>
<item><emph>best</emph> in that the sun was out.</item>
<item><emph>worst</emph> in that it was 39 degrees below zero.</item>
</list>
<section>
<title>Lunch Menu</title>
<list>
<item>ice cream</item>
<item>popsicles</item>
</list>
</section>
</section>
<section>
<title>The Second Day</title>
<p>Ditto the first day.</p>
</section></document>
XSLT File (poleeasy.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<HTML>
<HEAD>
<TITLE><xsl:value-of select="document/title"/></TITLE>
</HEAD>
<BODY>
<H1><xsl:value-of select="document/title"/></H1>
<xsl:apply-templates select="document/section"/>
</BODY>
</HTML>
</xsl:template>

<xsl:template match="section">
<DIV>
<H2><xsl:value-of select="title"/></H2>
<xsl:apply-templates />
</DIV>
</xsl:template>

<xsl:template match="p">
<P><xsl:apply-templates /></P>
</xsl:template>

<xsl:template match="list">
<UL>
<xsl:for-each select="item">
<LI><xsl:apply-templates /></LI>
</xsl:for-each>
</UL>
</xsl:template>

<xsl:template match="emph">
<I><xsl:apply-templates /></I>
</xsl:template>

<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="title"/>

</xsl:stylesheet>
Formatted Output



Processor Output

The white space has been adjusted for clarity.

<HTML>
<HEAD>
<TITLE>To the Pole and Back</TITLE>
</HEAD>
<BODY>
<H1>To the Pole and Back</H1>
<DIV>
<H2>The First Day</H2>
<P>It was the <I>best</I> of days, it was the <I>worst</I> of days.</P>
<UL>
<LI><I>best</I> in that the sun was out.</LI>
<LI><I>worst</I> in that it was 39 degrees below zero.</LI>
</UL>
<DIV>
<H2>Lunch Menu</H2>
<UL>
<LI>ice cream</LI>
<LI>popsicles</LI>
</UL>
</DIV>
</DIV>
<DIV>
<H2>The Second Day</H2>
<P>Ditto the first day.</P>
</DIV>
</BODY>
</HTML>


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
MariusI
post 13 Dec 2004, 15:23
Post #14


Membru autentic


Group: Members
Posts: 344
Joined: 24 March 03
From: Bucuresti




Daca vrei sa gasesti numai atributele cu un anumit tip de nume poti sa faci foarte usor asta cu expresii regulate. Daca imi spui cum arata numele pot sa iti fac eu expresia regulata.
Daca te grabesti, da un pm



--------------------
Solenza Scala
Dixit.
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 15:41
Post #15


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




am facut sa-mi afiseze si elementele recursive folosind exemplul de mai sus , cu template uri.

acum revin la intrebare initiala , cum fac sa caut un element dupa ce contine o bucata din id ul lui ?

si inca ceva. cum fac sa ma refer la tatal elementului pe care ma aflu eu ?


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
MariusI
post 13 Dec 2004, 16:24
Post #16


Membru autentic


Group: Members
Posts: 344
Joined: 24 March 03
From: Bucuresti




..cu riscul de a ma repeta: cu expresii regulate 04.gif
Adica: parcurgi tot tree-ul, cum vrei tu, si compari fiecare atribut cu o expresie regulata .


--------------------
Solenza Scala
Dixit.
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 16:26
Post #17


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




ok. uite in ce stadiu ma aflu:

eu ma aflu cu parser ul pe un element copil. vreau sa aflu ce id are elementul tata. cum fac asta ?


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 16:30
Post #18


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




adica eu am ceva de genul :

<doc>
<item/>
</doc>

unde item :
<item>
<h></h>
<b></b>
<item></item>
</item>

ma aflu inauntru unui item , vreau sa-l formatez conform cu un ss. pentru a face asta fac un choose , cu cate un div pt fiecare tip de formatare. determinarea tipului de formatare il fac dupa id ul parintelui.

si mai am o intrebare :

atributele sau variabilele se pot defini intr-un template si folosi in altul ?


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
MariusI
post 13 Dec 2004, 16:32
Post #19


Membru autentic


Group: Members
Posts: 344
Joined: 24 March 03
From: Bucuresti




Pai daca ai nodul intr-o structura XmlNode, e simplu, il ai in proprietatea ParentNode. Daca nu, poti sa-l obtii in ciclul in care parcurgi arborele si sa ti-l pasezi ca parametru..

Edit: acum am citit mai cu atentie postul, eu am avut impresia ca ai o rutina in vb.net sau c# si la aia ma ofeream sa ajut unsure.gif


--------------------
Solenza Scala
Dixit.
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 16:36
Post #20


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




pai am vrut sa-l pasez ca paramentru dar nu a vrut. nenorocitul grrrrrrr....

hai ca pana la urma il fac eu pe el laugh.gif

ancestor:: nu merge ? sau mai bine zis cum se utilizeaza ca la mine nu vrea ca in ecemplu laugh.gif


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 13 Dec 2004, 16:37
Post #21


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




nuuuuuuu... laugh.gif

eu vreau sa fac o transformare si o parcurgere direct in XSL folosind Xpath ul . ca dc era sa scriu niste cod ii trageam repede de tot .


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
MoneyTalks
post 13 Dec 2004, 16:46
Post #22


-


Group: Members
Posts: 2.712
Joined: 18 April 03
From: Ireland




Vezi aici e documentatie care iti explica ce si cum


--------------------
Lexus ES300H 2020
Religia a aparut cind primul ticalos s-a intilnit cu primul prost

Never underestimate the power of stupidity in large groups
User is offlineGalerie FotoPM
Go to the top of the page
+
neumann
post 13 Dec 2004, 19:31
Post #23


Membru autentic


Group: Members
Posts: 783
Joined: 6 November 03
From: Spermezeu




Am auzit ceva de XPath queries... Nu poti sa faci selectia in interogare?
Cred ca ar fi mai simplu, asta daca nu exista alte motive serioase sa faci cum vrei tu.


--------------------
... .. ..
Americanii il vor pe Ciolos.. i-au dat si viza!
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 14 Dec 2004, 09:32
Post #24


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




eu am un XML recursiv. am facut un XSL care citeste XML ul recursiv. acum am nevoie sa selectez elemente dupa id ul lor. de fapt dupa bucati din id ul lor. aici e pb mea. pentru a formata output ul imi trebuie sa pot face acest lucru si pentru a face aceasta trebuie sa selectez tot timpul elementul tata al frunzei pe care ma aflu . asta e tot.


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 14 Dec 2004, 10:07
Post #25


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




in XPATH pentru a selecta atributul elementului parinte se foloseste :
CODE

select="(parent::*/attribute::id)"

acum , despre partea a doua , cum pot sa caut un element dupa o parte din id ul sau?


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 14 Dec 2004, 10:22
Post #26


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




adica care ar fi wildcard ul pentru Xpath, pentru ca * nu functioneaza.


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 14 Dec 2004, 12:16
Post #27


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




am reusit sa imi selectez anumite ITEM uri dupa id ul lor, de fapt dupa parti din id ul lor folosind functiile pentru string uri . cautam , taiem , numram laugh.gif

idea este ca merge. nu la fel de frumos ca atunci cand as fi putut folosi wildcarduri (sau jokeri dc vreti) dar merge la fel de bine smile.gif


--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
neumann
post 14 Dec 2004, 17:56
Post #28


Membru autentic


Group: Members
Posts: 783
Joined: 6 November 03
From: Spermezeu




QUOTE(GeorgeB @ 14 Dec 2004, 12:22)
adica care ar fi wildcard ul pentru Xpath, pentru ca * nu functioneaza.
*



Pentru interogarile SQL 92, wilcarduri sunt
like '%ceva%'
like '?ceva?'
unde % reprezinta oricate caractere,
? fix un caracter.
Sper sa te-ajute.

* are sens de "toate atributele/campurile"



--------------------
... .. ..
Americanii il vor pe Ciolos.. i-au dat si viza!
User is offlineGalerie FotoPM
Go to the top of the page
+
GeorgeB
post 14 Dec 2004, 17:57
Post #29


the 7 stars of Pleiades constellation


Group: Members
Posts: 1.870
Joined: 7 January 03
From: Bucuresti




in SQL stiu si io .. laugh.gif

problema este in Xpath wink.gif ca acolo imi trebuie wildcardurile wink.gif



--------------------
SUBARU Legacy 2.5 - ---
L7 2.5 all in black - edition -
User is offlineGalerie FotoPM
Go to the top of the page
+
neumann
post 14 Dec 2004, 18:14
Post #30


Membru autentic


Group: Members
Posts: 783
Joined: 6 November 03
From: Spermezeu




Am presupus ca ai datele intr-un sql server si folosesti clauza "for XML" dupa care afisezi cu ajutorul xsl.

Pe de alta parte, daca lucrezi procedural, atunci tre' sa cauti o functie de genul strcmp(), nu cred sa ai wildcard-uri. Adica compari stringuri, ceea ce se pare ca ai facut deja wink.gif.

This post has been edited by cristianco2002: 14 Dec 2004, 18:23


--------------------
... .. ..
Americanii il vor pe Ciolos.. i-au dat si viza!
User is offlineGalerie FotoPM
Go to the top of the page
+
Reply to this topicTopic OptionsStart new topic


1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
 

Lo-Fi Version  Harta site  Parteneri  Jocuri online  Curs Valutar  HRH Haine din lana merinos Time is now: 24th July 2025 - 01:19
Forum Renault