Subject: Fw: [xsl] newbie question From: "Roma Yankin" <polfin@xxxxxxxx> Date: Sat, 11 May 2002 20:36:06 +0400 |
----- Original Message ----- From: "Mark Hutchinson" <markh@xxxxxxxxxxxxxxxxxxxxxxxx> To: "XSL-list" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Saturday, May 11, 2002 12:47 AM Subject: [xsl] newbie question > I'm sure this will be a "no brainer" for those that have been using XSLT for > more than an hour or so - here goes ... > > > I have the following XML > > ============= > > <proof aaa="111" bbb="222" ccc="333"> > ... > </proof> > > ============= > > I assume that if I use xsl:element and xsl:attribute I can output the tag > and its attributes. I have tried copy-of but that copies the whole tag, > attributes and its contents but, it seems I can't do anything to the tags > that are contained within "proof". > > If my assumption is correct about xsl:element / attribute how can I > reproduce an arbitrary set of attributes? > The easiest way is to write smth like that: <xsl:value-of select="//proof/attribute::ccc"/>, specifying the attribute u need but it might look mysterious to a newcomer so here is introduction in brief: XSLT implements XPath language for addressing parts of an XML document (nodes and their attributes). XPath is everything you see inside either “match” or “select” or “test” attributes of XSLT elements. It includes several functions to work with strings, numbers, and boolean expressions. References both for XSLT and XPath (and many more ;) can be found at http://msdn.microsoft.com/downloads/sample.asp?url=/msdn-files/027/001/766/m sdncompositedoc.xml actually this the msxml4 download page, the package includes references. A few words about code as far as it comes with out comments. --When “/” operator appears on the start that means that children should be selected from the root node otherwise it -selects first child of an element --“*” operator selects all elements regardless of the element name --“.” Operator identifies current selection --“@” operator actually is a prefix for an attribute name you must use it whenever you want to select an attribute --to locate some far away element XPath uses axes. --There are 13 types of axes. In my sample i used only four (child, descendant, ancestor and attribute) The rest is quite thoroughly described in thousands of tutorials and can found anywhere :) So here is the sample that demonstrates how to access elements and their attributes. XSLT implements XPath language for addressing parts of an XML document (nodes and their attributes). XPath is everything you see inside either “match” or “select” or “test” attributes of XSLT elements. It includes several functions to work with strings, numbers, and boolean expressions. References both for XSLT and XPath (and many more ;) can be found at http://msdn.microsoft.com/downloads/sample.asp?url=/msdn-files/027/001/766/m sdncompositedoc.xml actually this the msxml4 download page, the package includes references. A few words about code as far as it comes with out comments. --When “/” operator appears on the start that means that children should be selected from the root node otherwise it -selects first child of an element --“*” operator selects all elements regardless of the element name --“.” Operator identifies current selection --“@” operator actually is a prefix for an attribute name you must use it whenever you want to select an attribute --to locate some far away element XPath uses axes. --There are 13 types of axes. In my sample i used only four (child, descendant, ancestor and attribute) The rest is quite thoroughly described in thousands of tutorials and can found anywhere :) So here is the sample that demonstrates how to access elements and their attributes. XML file ---------------------------------------------- <?xml-stylesheet type="text/xsl" href="xsl2.xsl"?> <root> <proof aaa="111" bbb="222" ccc="333"> <proofchild name="child"> proof child text </proofchild> <proofchild2 name="child2" bbb="pcbbb"/> </proof> </root> XSL file ---------------------------------------------- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html> <body> <table border="1"> <tr> <td> Name </td> <td> Children </td> <td> Descendants </td> <td> Ancestors </td> <td> Attribbutes </td> <td> Data </td> </tr> <xsl:apply-templates/> </table> </body> </html> </xsl:template> <xsl:template match="*"> <tr> <td> <b><xsl:value-of select="name()"/></b> </td> <td> <xsl:for-each select="child::*"> <xsl:value-of select="name()"/><br/> </xsl:for-each> </td> <td> <xsl:for-each select="descendant::*"> <xsl:value-of select="name()"/><br/> </xsl:for-each> </td> <td> <xsl:for-each select="ancestor::*"> <xsl:value-of select="name()"/><br/> </xsl:for-each> </td> <td> <xsl:for-each select="@*"> <xsl:value-of select="name()"/>==<xsl:value-of select="."/><br/> </xsl:for-each> </td> <td> <xsl:for-each select="text()"> <xsl:value-of select="."/> </xsl:for-each> </td> </tr> <xsl:apply-templates select="*"/> </xsl:template> </xsl:stylesheet> Hope this helps, Regards Roman. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] newbie question, David Carlisle | Thread | [xsl] Newbie Question, Varley, Roger |
Re: [xsl] newbie question, David Carlisle | Date | [xsl] Can i have one XML referring , Suman . Sathyanaraya |
Month |