Hello XML gurus and pros. I have a question how to style an xml tree if the tree is like that:
1. ROW
Name
Surname
Type
2. ROW
Name
Surname
Type
3. ROW
ID
Name
Surname
I need to write xslt code that it show ROW 1(famous) and ROW 2(famous), but did not show ROW 3, and filter all ROW that did not have ID field in the tree, so answer must be that code will show Row1 and Row2. So how to do that ?
Code example here:
Some example, i can’t provide original xml file, because it’s secure information. Thanks for reply try to give you example:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="test.xsl" ?>
<testdocument>
<famous>
<name>Bob</name>
<surname>Bobby</surname>
<type>Human</type>
</famous>
<famous>
<name>Ted</name>
<surname>Teddy</surname>
<type>Human</type>
</famous>
<famous>
<name>Snake</name>
<surname>Anaconda</surname>
<type>Reptile</type>
<ID>ANIMAL</ID>
</famous>
</testdocument>
And i need to output famous leaf first and second but not ouput third leaf where ID is set to something. So i need output all but not famous leaf where is ID set to something, hope that i asked correctly. The possible ouput:
Bob
Bobby
Human
Ted
Teddy
Human
And that’s it.
This is the XSLT I have so far:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">
<html>
<head>
<title></title>
</head>
<body>
<!-- Here i think something must be written as condition that
ID field not be taken, and ROw3 name and surname not be shown too..-->
<xsl:for-each select="famous[ID != 0]">
<xsl:value-of select="NAME"/>
<xsl:value-of select="SURNAME"/>
<xsl:value-of select="TYPE"/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Please try the following XSLT:
Result when run on your sample data: