[oXygen-user] XSL transformation

George Cristian Bina
Wed Nov 12 02:26:31 CST 2003


Dear Aga,

When you want XSLT help it is good to provide not only your input document
but also your stylesheet and the expected output. Also when you mention an
XPath expression it is very important to know the context in which that
expression is executed.

Please find a sample that might help you. It prints the co_author content
for each book:

sample.xml:
<?xml version="1.0" encoding="UTF-8"?>
<books>
  <book>
    <author/>
    <co_author>c1</co_author>
    <co_author>c2</co_author>
    <co_author>c3</co_author>
  </book>
  <book>
    <author/>
    <co_author>c4</co_author>
  </book>
  <book>
    <author/>
    <co_author>c5</co_author>
  </book>
</books>

sample.xsl
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
  <xsl:template match="/">
    <result>
      <xsl:for-each select="//book">
        Book[<xsl:value-of select="position()"/>]
        <xsl:for-each select="co_author">
          <xsl:value-of select="."/>
        </xsl:for-each>
      </xsl:for-each>
    </result>
  </xsl:template>
</xsl:stylesheet>

Result:
<?xml version="1.0" encoding="utf-8"?><result>
        Book[1]
        c1c2c3
        Book[2]
        c4
        Book[3]
        c5</result>

You may also look over an XSL tutorial:

http://www.w3schools.com/xsl/
http://www.zvon.org/xxl/XSLTutorial/

Best Regards,
 George

----- Original Message -----
From: "Aga Shirazi" <>
To: <>
Sent: Tuesday, November 11, 2003 5:32 PM
Subject: [oXygen-user] XSL transformation


> Guys,
>
> Sorry about not being clear, earlier. Here is a sample of my XML file.
>
> <book>
> <author></author>
> <co_author></co_author>
> <co_author></co_author>
> <co_author></co_author>
> </book>
>
> <book>
> <author></author>
> <co_author></co_author>
> </book>
>
> <book>
> <author></author>
> <co_author></co_author>
> </book>
>
> .....
> (n number of books)
>
>
> I tried using <xsl:for-each select="author/co_author"/> along with
> <xsl:value-of select="//co_author"/> but it ittirates through the whole
> sheet and repeats just the first co-outhor.
>
> I hope you guys have understood what im say.
>
> Thanks
> Aga Shirazi
>
>
>
>
> *****************************************************************
>
> you wrote
>
> Dear Aga,
>
> There are a lot of possible answers and one cannot know what fits best
your
> needs unless you provide more details. Please consider posting a cut down
> sample that shows your problem.
>
> Sure you do not need to rename the author tags as author1, author2, etc.
> you can access each of them separately. For instance if you use an XPath
> expression like //author you can access all the author elements in your
> input document. If you want to iterate through them you can use
> Code:
>
> <xsl:for-each select="//author">...</xsl:for-each>
>
>
> You can have a template that matches author an if you issue
apply-templates
> that will act on author elements that template will be activated.
> If you want to access the first three author elements then //author[1],
> //author[2] and //author[3] will select them respectivelly.
>
> Best Regards,
> George
> _______________________________________________
> oXygen-user mailing list
> 
> http://www.oxygenxml.com/mailman/listinfo/oxygen-user
>



More information about the oXygen-user mailing list