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

  • Home
  • SEARCH
  • 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 3631588
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:24:59+00:00 2026-05-19T00:24:59+00:00

I have xml/rdf file which I get from service. So, I need to transform

  • 0

I have xml/rdf file which I get from service. So, I need to transform it to html block via XSL.

Here is part of xml/rdf file:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:c="http://s.opencalais.com/1/pred/">
    <rdf:Description rdf:about="http://d.opencalais.com/dochash-1/f1a1cace-8df1-3247-b8e2-331a8fa8363d/Instance/2">
        <rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/InstanceInfo"/>
        <c:docId rdf:resource="http://d.opencalais.com/dochash-1/f1a1cace-8df1-3247-b8e2-331a8fa8363d"/>
        <c:subject rdf:resource="http://d.opencalais.com/comphash-1/f69211ed-b366-31a8-9e04-b85c50b8e0a5"/><!--Company: Zila Inc.; -->
        <c:detection>[                PHOENIX, March 28 /PRNewswire/ -- ]Zila, Inc.[ (Nasdaq: ZILA) Chairman and President Joseph]</c:detection>
        <c:prefix>                PHOENIX, March 28 /PRNewswire/ -- </c:prefix>
        <c:exact>Zila, Inc.</c:exact>
        <c:suffix> (Nasdaq: ZILA) Chairman and President Joseph</c:suffix>
        <c:offset>131</c:offset>
        <c:length>10</c:length>
    </rdf:Description>
    <rdf:Description rdf:about="http://d.opencalais.com/dochash-1/f1a1cace-8df1-3247-b8e2-331a8fa8363d/Instance/3">
        <rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/InstanceInfo"/>
        <c:docId rdf:resource="http://d.opencalais.com/dochash-1/f1a1cace-8df1-3247-b8e2-331a8fa8363d"/>
        <c:subject rdf:resource="http://d.opencalais.com/comphash-1/f69211ed-b366-31a8-9e04-b85c50b8e0a5"/><!--Company: Zila Inc.; -->
        <c:detection>[March 28 /PRNewswire/ -- Zila, Inc. (Nasdaq: ]ZILA[) Chairman and President Joseph Hines announced]</c:detection>
        <c:prefix>March 28 /PRNewswire/ -- Zila, Inc. (Nasdaq: </c:prefix>
        <c:exact>ZILA</c:exact>
        <c:suffix>) Chairman and President Joseph Hines announced</c:suffix>
        <c:offset>151</c:offset>
        <c:length>4</c:length>
    </rdf:Description>
    <rdf:Description rdf:about="http://d.opencalais.com/comphash-1/f69211ed-b366-31a8-9e04-b85c50b8e0a5">
        <rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/Company"/>
        <c:name>Zila Inc.</c:name>
        <c:nationality>N/A</c:nationality>
    </rdf:Description>
    <rdf:Description rdf:about="http://d.opencalais.com/pershash-1/31337438-fcbd-3137-9705-ef2f1a752b88">
        <rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/Person"/>
        <c:name>Joseph Hines</c:name>
        <c:persontype>economic</c:persontype>
        <c:nationality>N/A</c:nationality>
        <c:commonname>Joseph Hines</c:commonname>
    </rdf:Description>
    ...
</rdf:RDF>

So, I have to build html from it. Html consists from entities lists, which have title and items.

Titles are the last word in <rdf:type> node’s attribute.
Expamle:

<rdf:Description rdf:about="http://d.opencalais.com/pershash-1/31337438-fcbd-3137-9705-ef2f1a752b88">
            <rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/Person"/>
            <c:name>Joseph Hines</c:name>
            <c:persontype>economic</c:persontype>
            <c:nationality>N/A</c:nationality>
            <c:commonname>Joseph Hines</c:commonname>
        </rdf:Description>

This node have to be transformed to

<div class="Block">
    <div class="Header Person">Person</div>
    <div class="Item">Joseph Hines</div> 
</div>

So, I have lots of such blocks, which have Person (or another) Header and Item in <c:name> node.

How can I transform this xml/rdf to html blocks and place all items with same header (e.g. Person) to same block?

It should looks like

<div class="Block">
    <div class="Header Person">Person</div>
    <div class="Item">Joseph Hines</div> 
    <div class="Item">another item</div>
    ...
</div>
<div class="Block">
    <div class="Header Company">Company</div>
    <div class="Item">Zila Inc.</div> 
    <div class="Item">another company item</div>
    ...
</div>
...

Sorry, If the problem isn’t clear. I’ll answer to all questions to help understand my problem.

Thanks in advance.

  • 1 1 Answer
  • 2 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-19T00:25:00+00:00Added an answer on May 19, 2026 at 12:25 am

    This XSLT:

    <xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                xmlns:c="http://s.opencalais.com/1/pred/"
                exclude-result-prefixes="rdf c">
    <xsl:output method="html" indent="yes"/>
    <xsl:strip-space elements="*"/>
    
    <xsl:key name="entityByType" match="rdf:Description" use="substring-after(rdf:type/@rdf:resource, 'type/em/e/')"/>
    
    <xsl:template match="/*">
        <xsl:apply-templates select="key('entityByType', 'Person')[1]"/>
        <xsl:apply-templates select="key('entityByType', 'Company')[1]"/>
    </xsl:template>
    
    <xsl:template match="rdf:Description">
        <div class="block">
            <xsl:variable name="entityType" select="substring-after(rdf:type/@rdf:resource, 'type/em/e/')"/>
            <div class="header {$entityType}">
                <xsl:value-of select="$entityType"/>
            </div>
            <xsl:apply-templates select="key('entityByType', $entityType)" mode="inner-content"/>
        </div>
    </xsl:template>
    
    <xsl:template match="rdf:Description" mode="inner-content">
        <div class="item">
            <xsl:value-of select="c:name"/>
        </div>
    </xsl:template>
    
    </xsl:stylesheet>
    

    Applied to a more descriptive input XML:

    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:c="http://s.opencalais.com/1/pred/">
    <rdf:Description rdf:about="http://d.opencalais.com/dochash-1/f1a1cace-8df1-3247-b8e2-331a8fa8363d/Instance/2">
        <rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/InstanceInfo"/>
        <c:docId rdf:resource="http://d.opencalais.com/dochash-1/f1a1cace-8df1-3247-b8e2-331a8fa8363d"/>
        <c:subject rdf:resource="http://d.opencalais.com/comphash-1/f69211ed-b366-31a8-9e04-b85c50b8e0a5"/><!--Company: Zila Inc.; -->
        <c:detection>[                PHOENIX, March 28 /PRNewswire/ -- ]Zila, Inc.[ (Nasdaq: ZILA) Chairman and President Joseph]</c:detection>
        <c:prefix>                PHOENIX, March 28 /PRNewswire/ -- </c:prefix>
        <c:exact>Zila, Inc.</c:exact>
        <c:suffix> (Nasdaq: ZILA) Chairman and President Joseph</c:suffix>
        <c:offset>131</c:offset>
        <c:length>10</c:length>
    </rdf:Description>
    <rdf:Description rdf:about="http://d.opencalais.com/dochash-1/f1a1cace-8df1-3247-b8e2-331a8fa8363d/Instance/3">
        <rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/InstanceInfo"/>
        <c:docId rdf:resource="http://d.opencalais.com/dochash-1/f1a1cace-8df1-3247-b8e2-331a8fa8363d"/>
        <c:subject rdf:resource="http://d.opencalais.com/comphash-1/f69211ed-b366-31a8-9e04-b85c50b8e0a5"/><!--Company: Zila Inc.; -->
        <c:detection>[March 28 /PRNewswire/ -- Zila, Inc. (Nasdaq: ]ZILA[) Chairman and President Joseph Hines announced]</c:detection>
        <c:prefix>March 28 /PRNewswire/ -- Zila, Inc. (Nasdaq: </c:prefix>
        <c:exact>ZILA</c:exact>
        <c:suffix>) Chairman and President Joseph Hines announced</c:suffix>
        <c:offset>151</c:offset>
        <c:length>4</c:length>
    </rdf:Description>
    <rdf:Description rdf:about="http://d.opencalais.com/comphash-1/f69211ed-b366-31a8-9e04-b85c50b8e0a5">
        <rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/Company"/>
        <c:name>Zila Inc.1</c:name>
        <c:nationality>N/A</c:nationality>
    </rdf:Description>
    <rdf:Description rdf:about="http://d.opencalais.com/pershash-1/31337438-fcbd-3137-9705-ef2f1a752b88">
        <rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/Person"/>
        <c:name>Joseph Hines1</c:name>
        <c:persontype>economic</c:persontype>
        <c:nationality>N/A</c:nationality>
        <c:commonname>Joseph Hines</c:commonname>
    </rdf:Description>
    <rdf:Description rdf:about="http://d.opencalais.com/comphash-1/f69211ed-b366-31a8-9e04-b85c50b8e0a5">
        <rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/Company"/>
        <c:name>Zila Inc.2</c:name>
        <c:nationality>N/A</c:nationality>
    </rdf:Description>
    <rdf:Description rdf:about="http://d.opencalais.com/pershash-1/31337438-fcbd-3137-9705-ef2f1a752b88">
        <rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/Person"/>
        <c:name>Joseph Hines2</c:name>
        <c:persontype>economic</c:persontype>
        <c:nationality>N/A</c:nationality>
        <c:commonname>Joseph Hines</c:commonname>
    </rdf:Description>
    <rdf:Description rdf:about="http://d.opencalais.com/comphash-1/f69211ed-b366-31a8-9e04-b85c50b8e0a5">
        <rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/Company"/>
        <c:name>Zila Inc.3</c:name>
        <c:nationality>N/A</c:nationality>
    </rdf:Description>
    <rdf:Description rdf:about="http://d.opencalais.com/pershash-1/31337438-fcbd-3137-9705-ef2f1a752b88">
        <rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/Person"/>
        <c:name>Joseph Hines3</c:name>
        <c:persontype>economic</c:persontype>
        <c:nationality>N/A</c:nationality>
        <c:commonname>Joseph Hines</c:commonname>
    </rdf:Description>
    </rdf:RDF>
    

    Produces this correct result:

    <div class="block">
        <div class="header Person">Person</div>
        <div class="item">Joseph Hines1</div>
        <div class="item">Joseph Hines2</div>
        <div class="item">Joseph Hines3</div>
    </div>
    <div class="block">
        <div class="header Company">Company</div>
        <div class="item">Zila Inc.1</div>
        <div class="item">Zila Inc.2</div>
        <div class="item">Zila Inc.3</div>
    </div>
    

    EDIT:

    <xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                xmlns:c="http://s.opencalais.com/1/pred/"
                exclude-result-prefixes="rdf c">
    <xsl:output method="html" indent="yes"/>
    <xsl:strip-space elements="*"/>
    
    <xsl:key name="entityByType" match="rdf:Description" use="substring-after(rdf:type/@rdf:resource, 'type/em/e/')"/>
    
    <xsl:template match="/*">
        <xsl:apply-templates select="
        rdf:Description[
        generate-id() = generate-id(key('entityByType', substring-after(rdf:type/@rdf:resource, 'type/em/e/')))
        ]"/>
    </xsl:template>
    
    <xsl:template match="rdf:Description">
        <div class="block">
            <xsl:variable name="entityType">
                <xsl:call-template name="substring-after-last">
                    <xsl:with-param name="input" select="rdf:type/@rdf:resource"/>
                    <xsl:with-param name="substr" select="'/'"/>
                </xsl:call-template>
            </xsl:variable>
            <div class="header {$entityType}">
                <xsl:value-of select="$entityType"/>
            </div>
            <xsl:apply-templates select="key('entityByType', $entityType)" mode="inner-content"/>
        </div>
    </xsl:template>
    
    <xsl:template match="rdf:Description" mode="inner-content">
        <div class="item">
            <xsl:value-of select="c:name"/>
        </div>
    </xsl:template>
    
    <xsl:template name="substring-after-last">
        <xsl:param name="input"/>
        <xsl:param name="substr"/>
        <xsl:variable name="temp" select="substring-after($input,$substr)"/>
        <xsl:choose>
            <xsl:when test="$substr and contains($temp,$substr)">
                <xsl:call-template name="substring-after-last">
                <xsl:with-param name="input"  select="$temp" />
                <xsl:with-param name="substr" select="$substr" />
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$temp"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
    </xsl:stylesheet>
    

    And the result:

    <div class="block">
        <div class="header InstanceInfo">InstanceInfo</div>
    </div>
    <div class="block">
        <div class="header Company">Company</div>
        <div class="item">Zila Inc.1</div>
        <div class="item">Zila Inc.2</div>
        <div class="item">Zila Inc.3</div>
    </div>
    <div class="block">
        <div class="header Person">Person</div>
        <div class="item">Joseph Hines1</div>
        <div class="item">Joseph Hines2</div>
        <div class="item">Joseph Hines3</div>
    </div>
    

    You can exclude any unnecessary types yourself or provide a criteria for such exclusion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this xml file, how can I create RDF triple from it using
I have some web services which return RDF file. Now I need to display
A similiar question was asked already here How to get nested RDF/XML from Jena?
Okay, to clarify, I have an XML/RDF file that describes data with a natural
So I have a JSON file, which is basically an ATOM XML encoded into
I have XML-request from web service. It looks like this. So, how can I
I have XML file which looks like this: <?xml version=1.0?> <results> <row id=100><name>name blah</name></row>
I have XML file with over 300 000 entries which my script has to
I have xml file with such structure: ... <outer> ... <inner/> ... </outer> ...
I have xml like this: <rule> <word>I</word> <word>need</word> <word>more</word> <marker> <word>money</word> </marker> <word>now</word> </rule>

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.