how to display the element attribute values (xml to pdf)

Here should go questions about transforming XML with XSLT and FOP.
JANA
Posts: 8

how to display the element attribute values (xml to pdf)

Wed Jan 18, 2006 9:59 am

Hello....
This is my xml file like this
<info>
<emp name="jana" id="1228"></emp>
</inf>

Iam converting xml file into pdf using FOP.

i need output like this:

name : jana
id : 1228

how to modify the xsl file.... please give the solution as soon as possible
Radu
Posts: 5994

Wed Jan 18, 2006 10:55 am

Hello Jana

For an xml file like:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<info>
   <emp name="name1" id="1228"></emp>
   <emp name="name2" id="1229"></emp>
</info>


The stylesheet could be something like:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="all-pages">
          <fo:region-body region-name="xsl-region-body" margin="0.7in" column-gap="0.25in"
            border="0.25pt solid gray" padding="6pt"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="all-pages">
        <fo:flow flow-name="xsl-region-body">
          <xsl:for-each select="//emp">
            <fo:block>
              name: <xsl:value-of select="@name"/>
            </fo:block>
            <fo:block>
              id: <xsl:value-of select="@id"/>
            </fo:block>
          </xsl:for-each>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
</xsl:stylesheet>


You have to create a scenario and apply the stylesheet over the xml file with fo-processing and save the result as pdf.

For more information about fo you can read this tutorial: http://www.renderx.com/tutorial.html and also check out the fo samples that come with Oxygen located in the samples/fo folder of the installation directory.

Regards, Radu

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 3 guests