RE: [PHP] XML -> XSLT transformation using XSLTProcessor class
| From: | Boyd, Todd M. | Date: | Fri, 20 Feb 2009 16:10:32 +0000 |
| Subject: | RE: [PHP] XML -> XSLT transformation using XSLTProcessor class | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-288634@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: th.heuer@gmail.com [mailto:th.heuer@gmail.com] On Behalf Of
> German Geek
> Sent: Friday, February 20, 2009 9:18 AM
> To: PHP General list
> Subject: [PHP] 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