| Author |
Message |
kutar Mini Game Hunter

Joined: 03 Jun 2004 Posts: 1327 Location: Techno Island
|
Posted: Tue Mar 18, 2008 1:13 am Post subject: XSLT Question: How can I get an element tag name list? |
|
|
I want to an xml inspector to do some statistic based on element tag name...
The book was talked about the method of doing math, but not many people taking about get a tag name list (they preferring process all the node/process the xml with known schema - not exlporing or inspecting xml)
Does anyone have good reference or have a xslt stylesheet for the xml inspectin purpose or xslt can give me a list of all element tag name?
thank you. _________________ Sleepless Cat‧The one looking for her path... |
|
| Back to top |
|
| |
LP-SolidRaven Dictator of the Dump

Joined: 06 Jun 2004 Posts: 7015 Location: The cheese is made out of moon
|
Posted: Tue Mar 18, 2008 5:42 am Post subject: |
|
|
You can always check the W3 website. You can be pretty sure all possible tags are listed there. You can find the one for XSLT 1 here. _________________
| Quote: |
<bart416> I just realized something
<bart416> we celebrate the fact that this piece of rock made one rotation around a glowing ball of plasma that is kept together due to its own gravity well
<njsg> HAPPY NEW YEAR
<Easter> ^^
|
|
|
| Back to top |
|
| |
exsanguination Forum Regular
Joined: 27 Apr 2005 Posts: 412 Location: Australia
|
Posted: Tue Mar 18, 2008 4:40 pm Post subject: Re: XSLT Question: How can I get an element tag name list? |
|
|
| kutar wrote: | I want to an xml inspector to do some statistic based on element tag name...
The book was talked about the method of doing math, but not many people taking about get a tag name list (they preferring process all the node/process the xml with known schema - not exlporing or inspecting xml)
Does anyone have good reference or have a xslt stylesheet for the xml inspectin purpose or xslt can give me a list of all element tag name?
thank you. |
This is really simple and you should be able to do it (if not go back to the start of your book )....I'm not going to give you code yet - if you don't have a solution in a week, then ill post an example.
So lets just think about what you need to do...you need a template that will match any element (or node) and output the name of that element.
Do you get what I'm hinting at?
http://www.zvon.org/xxl/XSLTreference/Output/ |
|
| Back to top |
|
| |
krt ...

Joined: 11 Jan 2005 Posts: 4607 Location: Australia
|
Posted: Sun Mar 23, 2008 6:23 am Post subject: |
|
|
He wants a list of tags for the specific XML document, not the tags available for XSL stylesheets.
kutar, you didn't seem to explain much about what you want or your intent. For all I know, this could be all you are after...
| Code: | <xsl:template match="*">
<xsl:text><xsl:value-of select="name()"><br /></xsl:text>
</xsl:template> |
(maybe with some sprucing up or with a counter)
How about some sample input and desired output? |
|
| Back to top |
|
| |
LP-SolidRaven Dictator of the Dump

Joined: 06 Jun 2004 Posts: 7015 Location: The cheese is made out of moon
|
Posted: Sun Mar 23, 2008 10:49 am Post subject: |
|
|
| krt wrote: | | He wants a list of tags for the specific XML document, not the tags available for XSL stylesheets. |
Uhm, if you read that entire document there's a big change you'll know how to do it. Specifications are rather detailed... _________________
| Quote: |
<bart416> I just realized something
<bart416> we celebrate the fact that this piece of rock made one rotation around a glowing ball of plasma that is kept together due to its own gravity well
<njsg> HAPPY NEW YEAR
<Easter> ^^
|
|
|
| Back to top |
|
| |
exsanguination Forum Regular
Joined: 27 Apr 2005 Posts: 412 Location: Australia
|
Posted: Tue Mar 25, 2008 8:50 pm Post subject: |
|
|
| krt wrote: | He wants a list of tags for the specific XML document, not the tags available for XSL stylesheets.
kutar, you didn't seem to explain much about what you want or your intent. For all I know, this could be all you are after...
| Code: | <xsl:template match="*">
<xsl:text><xsl:value-of select="name()"><br /></xsl:text>
</xsl:template> |
(maybe with some sprucing up or with a counter)
How about some sample input and desired output? |
Yeah thats the basic idea...
But there is a slight trick...you need a specific template to match on text(), be cause text() is a type of node() you would also pick up the text in non empty elements as a node.
| Code: |
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" version="1.0" method="xml" />
<xsl:template match="/">
<ElementList>
<xsl:apply-templates />
</ElementList>
</xsl:template>
<xsl:template match="node()">
<Element Name="{name()}" />
<xsl:apply-templates />
</xsl:template>
<xsl:template match="text() | @* | comment()" />
</xsl:stylesheet>
|
|
|
| Back to top |
|
| |
|
|
|