Re: XML -> XSLT transformation using XSLTProcessor class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks a lot. Sorry but 5 minutes after sending this email i figured it out
myself. I didn't know how to answer my own message because i didn't get my
own message... Anyway, this worked for me:

<xsl:for-each select="//elementA | //elementB">
  <xsl:value-of select="name(.)" />
</xsl:for-each>

Hope this helps someone else...

Thanks again.

Tim

Tim-Hinnerk Heuer

http://www.ihostnz.com
Bill Watterson  - "There is not enough time to do all the nothing we want to
do."

2009/2/21 Boyd, Todd M. <tmboyd1@xxxxxxxx>

> > -----Original Message-----
> > From: th.heuer@xxxxxxxxx [mailto:th.heuer@xxxxxxxxx] On Behalf Of
> > German Geek
> > Sent: Friday, February 20, 2009 9:18 AM
> > To: PHP General list
> > Subject:  XML -> XSLT transformation using XSLTProcessor class
> >
> > Hi All,
> >
> > We are trying to import some xml data into the database. My idea was to
> > make
> > an xslt and then transform the xml to php code which generates the
> > queries
> > necessary and then gets evaled as php code for the actual import...
> >
> > Anyway, i got it working (mostly)!
> >
> > But i need to get the current element name with x-path. So i have the
> > following:
> >
> > <rootEl>
> >   <elementA><childOfA>some data 1</childOfA></elementA>
> >   <elementB><childOfB>some data 2</childOfB></elementB>
> >   <elementB><childOfB>some data 3</childOfB></elementB>
> >   <elementA><childOfA>some data 4</childOfA></elementA>
> >   <elementA><childOfA>some data 5</childOfA></elementA>
> > </rootEl>
> >
> > <xsl:for-each select="//elementA | //elementB">
> >   // <xsl:value-of select="childOfA" /> WORKS and gives the value of
> > childOfA (e.g. some data 1)
> >   //... the php code...
> > </xsl:for-each>
> >
> > In the php code, I need to get the element tag name of the current
> > element,
> > so either elementA or elementB. How can i get that in an x-path
> > expression?
> >
> > I know, this is not strictly a php question, but since the project is
> > in php
> > and this list has a very good response rate, i decided to ask here. I
> > already looked on the web for hours, but maybe i just don't have the
> > right
> > keywords.
> >
> > Please help. Thanks.
>
> I believe the name() XPath function is what you are looking for. It's been
> a while since I've worked with XPath query strings, but I believe
> ".[name()]" will get you the current element's tag name. Keep in mind: I'm
> not sure if this works with namespaced tags (like <namespace:tagname />),
> but I have not tested this to be sure.
>
> HTH,
>
>
> // Todd
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux