Subject: simple XSLT question
Posted By: _thinking Post Date: 1/24/2006 6:47:55 AM
Hi,

I have xml file like:

<tag1>
  <tag11>
    <strValue value="val1"/>
    <strValue2 value="val1_2"/>
  </tag1>
  <tag12>
    <strValue value="val2"/>
    <strValue2 value="val2_2"/>
  </tag12>
  <tagAAA>
    <strValue value="val3"/>
    <strValue2 value="val3_2"/>
  </tagAAA>
  ...
</tag1>

I need to form XSL file to output outer tags( tag11, tag12,tag13 ) as table names and strValue1, strValue2 as tables' headers.

I don't know what tag names are when creating XSL.

Thanks a lot, waiting for answers
Reply By: mhkay Reply Date: 1/24/2006 7:49:05 AM
Do you know what output (HTML, presumably) you want to generate? If you don't, it's not worth even thinking about the XSLT code needed (never start writing any program if you don't know what you want the output to look like).

Then, if you still have problems writing the XSLT, give us some clues as to where you are having difficulty. Show us what you tried and where you got stuck. We're here to help you over your learning difficulties, not to write the code for you.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply By: _thinking Reply Date: 1/24/2006 8:30:32 AM
quote:
Originally posted by mhkay

Do you know what output (HTML, presumably) you want to generate? If you don't, it's not worth even thinking about the XSLT code needed (never start writing any program if you don't know what you want the output to look like).

Then, if you still have problems writing the XSLT, give us some clues as to where you are having difficulty. Show us what you tried and where you got stuck. We're here to help you over your learning difficulties, not to write the code for you.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference



I need an HTML file, where first-level tags are table names, second-level are headers for each table, and 3rd-level - are values in the table. I don't know how to get a list of tag names (not values!) inside specific tag.

Reply By: mhkay Reply Date: 1/24/2006 9:24:42 AM
You can get a list of the elements within a given element using child::* (or simply *) and you can get the name of an element using the name() function. I'm afraid I don't really know what you mean when you talk about a "second level tag" in HTML - you'll have to explain more clearly.

It's dangerous to use the term "tag" when talking about XSLT's data model, by the way. XSLT works in terms of a tree containing nodes. Tags appear in source XML only, and each element node in the tree usually corresponds to two tags, a start tag and an end tag. When people talk about the "content of a tag" it's not clear whether they mean the name of the element or the content of the element.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply By: _thinking Reply Date: 1/24/2006 9:41:04 AM
quote:
Originally posted by mhkay

You can get a list of the elements within a given element using child::* (or simply *) and you can get the name of an element using the name() function. I'm afraid I don't really know what you mean when you talk about a "second level tag" in HTML - you'll have to explain more clearly.

It's dangerous to use the term "tag" when talking about XSLT's data model, by the way. XSLT works in terms of a tree containing nodes. Tags appear in source XML only, and each element node in the tree usually corresponds to two tags, a start tag and an end tag. When people talk about the "content of a tag" it's not clear whether they mean the name of the element or the content of the element.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference



Thanks. Using <xsl:for-each select="node_my/*"> actually solved my problem. in combination with <xsl:value-of select="name(.)"/> I've got what I wanted.
Thanks again.


Go to topic 38980

Return to index page 387
Return to index page 386
Return to index page 385
Return to index page 384
Return to index page 383
Return to index page 382
Return to index page 381
Return to index page 380
Return to index page 379
Return to index page 378