Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 672989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:32:44+00:00 2026-05-14T00:32:44+00:00

I need to generate an xsl table for the xml below, for attributes fname

  • 0

I need to generate an xsl table for the xml below, for attributes fname and lname. I guess I have done something wrong in xpath. Could someone help me out by writing an xsl table for the xml below..

<sparql>
    <head>
        <variable name="s"/>
        <variable name="fname"/>
        <variable name="lname"/>
    </head>
    <results>
        <result>
            <binding name="s">
                <uri>http://tn.gov.in/Person/41</uri>
            </binding>
            <binding name="fname">
                <literal>G</literal>
            </binding>
            <binding name="lname">
                <literal>Vn</literal>
            </binding>
        </result>
        <!-- more result elements -->
    </results>
</sparql>

like i have an servlet which queries a semantic data , using jena… the output of the servlet is above xml… while setting the output format Jena has an option in which the XML can be styled mapping the xsl file..

now when i used lachlan’s example i got output as i posted in that comment..
nothing , my output must be in the form of an Table in which fname,lname should be displayed

like

fname             lname
------------------------
M           v
G         v

etc…

what’s the mistake i must have done ?
this is my xsl:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="UTF-8"/>

    <xsl:template match="sparql/results">
        <html>
            <head><title>persons</title>
            </head>
            <body>
                <table width="40%" border="1">
                    <THEAD>
                        <TR>
                            <TD><B>first name</B></TD>
                            <TD><B>last name</B></TD>
                        </TR>
                    </THEAD> 
                    <TBODY>
                        <xsl:for-each select="result">
                            <TR>    
                                <TD><xsl:value-of select="binding[@name='fname']/literal/text()" /></TD>     
                                <TD><xsl:value-of select="binding[@name='fname']/literal/text()" /></TD> 

                            </TR>
                        </xsl:for-each>
                    </TBODY>
                </table>
            </body>
        </html>
    </xsl:template>

</xsl:stylesheet>

My output is:

http://tn.gov.in/Person/41 Gn http://tn.gov.in/Person/43 Vn http://tn.gov.in/Person/37 Mn http://tn.gov.in/Person/39 Vn

i dint put the name=’s’ in the xsl def.. but i am getting that also in the output that too wihtout formatting as table..

YES i have nampespace for the root sparql..

<sparql xmlns="http://www.w3.org/2005/sparql-results#">
  <head>
    <variable name="s"/>
    <variable name="fname"/>
    <variable name="lname"/>
    <variable name="title"/>
    <variable name="mno"/>
    <variable name="community"/>

  </head>
  <results>
    <result>
      <binding name="s">
        <uri>http://tn.gov.in/Person/45</uri>
      </binding>
      <binding name="fname">
        <literal>/literal>

      </binding>
      <binding name="lname">
        <literal>K</literal>
      </binding>
      <binding name="title">
        <literal>Mr.</literal>
      </binding>
      <binding name="mno">

        <literal>876876</literal>
      </binding>
      <binding name="community">
        <literal>Fe</literal>
      </binding>
    </result>

how should i match template now?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:32:44+00:00Added an answer on May 14, 2026 at 12:32 am

    Your stylesheet has only has a single template rule: match="sparql/results" which should be matched. Does your input document contain namespaces which are not shown in the example?

    If your xml elements are in a namespace, even if it is the default namespace for the document, you must use namespace prefixes in any XPath expressions and template match rules. It is the namespace uri and not the prefix that matters. Note that attributes will not be in the default namespace, they only have a namespace if their name has a prefix.

    <xsl:stylesheet version="1.0"
                    xmlns:s="http://www.w3.org/2005/sparql-results#"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:template match="s:results">
    

    The built-in template rules generate the output that you were seeing, since they:

    • match all templates, and perform an apply-templates
    • copy text nodes to output

    I have added a rule to match /, and then explicitly select the desired elements at each step.

    This example produces a HTML table from your input, containing columns for first name and last name.

    <xsl:stylesheet version="1.0"
        xmlns:s="http://www.w3.org/2005/sparql-results#"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="html" encoding="UTF-8"/>
    
        <xsl:template match="/">
            <html>
                <head><title>persons</title>
                </head>
                <body>
                    <xsl:apply-templates select="s:sparql/s:results" />
                </body>
            </html>
        </xsl:template>
    
    
        <xsl:template match="s:results">
            <table>
                <thead>
                    <tr>
                        <td>
                            <xsl:text>Link</xsl:text>
                        </td>
                        <td>
                            <xsl:text>First name</xsl:text>
                        </td>
                        <td>
                            <xsl:text>Last name</xsl:text>
                        </td>
                    </tr>
                </thead>
                <tbody>
                    <xsl:apply-templates />
                </tbody>
            </table>
        </xsl:template>
    
        <xsl:template match="s:result">
            <tr>
                <td>
                    <a href="{s:binding[@name='s']/s:uri}">
                        <xsl:value-of select="s:binding[@name='s']/s:uri" />
                    </a>
                </td>
                <td>
                    <xsl:value-of select="s:binding[@name='fname']/s:literal" />
                </td>
                <td>
                    <xsl:value-of select="s:binding[@name='lname']/s:literal" />
                </td>
            </tr>
        </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.