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 8920545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:17:58+00:00 2026-06-15T06:17:58+00:00

If I were to have the following XML document… <?xml version=1.0?> <document> <title>Foobar</title> <article>

  • 0

If I were to have the following XML document…

<?xml version="1.0"?>
<document>
  <title>Foobar</title>
  <article>
    Phasellus ultrices arcu suscipit velit laoreet eu dignissim 
    dolor pulvinar. Proin ac libero a diam laoreet iaculis nec eu risus.

    <ref url="http://en.wikipedia.org/wiki/FooBar">Foobar</ref> potenti. 
    Duis placerat laoreet est nec fringilla. Quisque vitae semper erat.
  </article>
</document>

…how would I translate the article element to the following?

<p>
  Phasellus ultrices arcu suscipit velit laoreet eu dignissim 
  dolor pulvinar. Proin ac libero a diam laoreet iaculis nec eu risus.

  <a href="http://en.wikipedia.org/wiki/FooBar">Foobar</a> potenti. 
  Duis placerat laoreet est nec fringilla. Quisque vitae semper erat.
</p>

Specifically, it’s the ref to a translation I’m interested in, since it’s embedded within a block of plain text.

  • 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-06-15T06:17:59+00:00Added an answer on June 15, 2026 at 6:17 am

    If you build upon the standard XSTL Identity Transform, this is a straight-forward task, you just need a template to match a ref element and output an a element instead.

    <xsl:template match="ref">
       <a>
          <xsl:apply-templates select="@*|node()"/>
       </a>
    </xsl:template>
    

    And to replace the attribute, you then have another template

    <xsl:template match="ref/@url">
       <xsl:attribute name="href">
          <xsl:value-of select="." />
       </xsl:attribute>
    </xsl:template>
    

    Note that if your ref element was guaranteed to always have an url attribute, you could also simplify those two templates into just one, like this:

    <xsl:template match="ref">
       <a href="{@url}">
          <xsl:apply-templates select="node()"/>
       </a>
    </xsl:template>
    

    You would then add other templates to replace any other elements as required, such as article being changed to p, and also a template to not output the title element.

    Here is the full XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:template match="/document">
             <xsl:apply-templates />
       </xsl:template>
    
       <xsl:template match="title" />
    
       <xsl:template match="article">
          <p>
             <xsl:apply-templates />
          </p>
       </xsl:template>
    
       <xsl:template match="ref">
          <a>
             <xsl:apply-templates select="@*|node()"/>
          </a>
       </xsl:template>
    
       <xsl:template match="ref/@url">
          <xsl:attribute name="href">
             <xsl:value-of select="." />
          </xsl:attribute>
       </xsl:template>
    
       <xsl:template match="@*|node()">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your sample XML, the following is output

    <p>
        Phasellus ultrices arcu suscipit velit laoreet eu dignissim 
        dolor pulvinar. Proin ac libero a diam laoreet iaculis nec eu risus.
    
        <a href="http://en.wikipedia.org/wiki/FooBar">Foobar</a> potenti. 
        Duis placerat laoreet est nec fringilla. Quisque vitae semper erat.
      </p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
I have the following xml document: <package> <title>セレニティー (字幕版)</title> ... </package> I am using
I have the following xml document: <?xml version=1.0 encoding=UTF-8?> <root> <data> <child1>&#160;Well, some spaces
I have the following XML document : <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE inventory SYSTEM books.dtd>
I have the following XML document <?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:issues='http://schemas.google.com/projecthosting/issues/2009' gd:etag='W/DEAERH47eCl7ImA9WhZTFEQ.'><id>http://code.google.com/feeds/issues/p/chromium/issues/full/921</id><published>2008-09-03T22:51:22.000Z</published><updated>2011-03-19T01:05:05.000Z</updated><title>Incorrect rendering</title><content
i am new to xquery. I have the following xml document : <?xml version=1.0
Consider we have the following xml document <?xml version=1.0 encoding=utf-8?> <Root> <Child /> </Root>
I have the following XML document: <?xml version=1.0 encoding=UTF-8?> <Offices id=0 enabled=false> <office />
I have the following XML document: <samlp:LogoutRequest ID=123456789 Version=2.0 IssueInstant=200904051217> <saml:NameID>@NOT_USED@</saml:NameID> <samlp:SessionIndex>abcdefg</samlp:SessionIndex> </samlp:LogoutRequest> I'd
I have the following XML document: <?xml version=1.0 encoding=UTF-8?> <cars> <car body=Wagon> <text>Red</text> </car>

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.