XML/xsl

Advertisement


Question
I have 2 questions:
1. How does one declare attributes in xsl? Eg
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="books.xsl"?>
<books>
  <book location="library">
  <title>OpenGL Programming Guide Fourth Edition</title>         
     <department>Development</department>
     <room>107</room>
  <publisher>Addison-Wesley</publisher>
  <year>2004</year>
  </book>
........... bla bla bla


Secondly, what's the difference between elements and attributes for xsl:value-of-tags?

Thanks a heap!

Answer
Hi,
1) To declare an element you use <xsl:element name="MyName">
To delcare an ettribute you use <xsl:attribute name="MyName">
Make sure the attribute is the FIRST thing you insert under an element (before any text or child elements)

2) xsl:value-of treats elements and attributes in the same manner - as nodes. It evaluates their text nodes.

Let me know if this helps,
Ziv

XML

All Answers


Ask Experts

Volunteer


Ziv Ben-Eliahu

Expertise

I can answer XSLT (XSL) questions - XML transformation. I like XPath and XQuery concepts. I know some XML parsing techniques.

Experience

2 years with XSLT (and related XPath)

Education/Credentials
M.Sc. from Ben-Gurion University

Past/Present Clients
I.D.I Technology

©2016 About.com. All rights reserved.