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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:21:09+00:00 2026-05-20T12:21:09+00:00

did a search for this and didn’t find an answer, so here goes… I

  • 0

did a search for this and didn’t find an answer, so here goes…

I have some xml similar to the following:

<?xml version="1.0" encoding="utf-8"?>
<footnote ref="1">
    <para>Here is some text about some guy who made
        <emphasis role="italic">fascinating</emphasis> comment I want to quote
        <blockquote> So I went to this place and met this guy....</blockquote>
        It seemed more interesting at the time.
    </para>
</footnote>

I want to use xslt to change it to a new schema (using new namespace prefix)

<?xml version="1.0" encoding="utf-8"?>
<nns:footnote ref="1">
    <nns:fn-para>Here is some text about some guy who made
        <nns:emph type="it">fascinating</nns:emph> comment I want to quote:
    </nns:fn-para>
    <nns:fn-blockquote>
        <nns:bq-para>So I went to this place and met this guy....</nns:bq-para>
    </nns:fn-blockquote>
    <nns:fn-para> It seemed more interesting at the time.</nns:fn-para>
</nns:footnote>

I’ve tried a few things…taking a para that’s a descendant of footnote and looping through the children, but that’s problematic because it isn’t only text nodes in the para, there are also emph tags, and I still don’t know how to place a child node up the tree and over in the result tree…doe that make sense?

  • 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-20T12:21:10+00:00Added an answer on May 20, 2026 at 12:21 pm

    EDIT: Small refactor and extended explanation.

    This stylesheet:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:nns="nns">
        <xsl:key name="kNodeByPrecedingBlock"
                 match="para/node()[not(self::blockquote)]"
                 use="generate-id(
                         (..|preceding-sibling::*[self::blockquote][1])[last()]
                      )"/>
        <xsl:template match="node()|@*">
            <xsl:copy>
                <xsl:apply-templates select="node()|@*"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="footnote">
            <nns:footnote>
                <xsl:apply-templates select="node()|@*"/>
            </nns:footnote>
        </xsl:template>
        <xsl:template match="para">
            <xsl:apply-templates select=".|blockquote" mode="group"/>
        </xsl:template>
        <xsl:template match="emphasis">
            <nns:emph>
                <xsl:apply-templates select="node()|@*"/>
            </nns:emph>
        </xsl:template>
        <xsl:template match="emphasis/@role">
            <xsl:attribute name="type">
                <xsl:value-of select="substring(.,1,2)"/>
            </xsl:attribute>
        </xsl:template>
        <xsl:template match="blockquote">
            <nns:fn-blockquote>
                <nns:bq-para>
                    <xsl:apply-templates/>
                </nns:bq-para>
            </nns:fn-blockquote>
        </xsl:template>
        <xsl:template match="para" mode="group" name="makePara">
            <xsl:variable name="vGroup"
                 select="key('kNodeByPrecedingBlock',generate-id())"/>
            <xsl:if test="$vGroup">
                <nns:fn-para>
                    <xsl:apply-templates select="$vGroup"/>
                </nns:fn-para>
            </xsl:if>
        </xsl:template>
        <xsl:template match="*" mode="group">
            <xsl:apply-templates select="."/>
            <xsl:call-template name="makePara"/>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <nns:footnote ref="1" xmlns:nns="nns">
       <nns:fn-para>Here is some text about some guy who made 
          <nns:emph type="it">fascinating</nns:emph> comment I want to quote 
       </nns:fn-para>
       <nns:fn-blockquote>
          <nns:bq-para> So I went to this place and met this guy....</nns:bq-para>
       </nns:fn-blockquote>
       <nns:fn-para>         It seemed more interesting at the time. 
       </nns:fn-para>
    </nns:footnote>
    

    Note: Identity rule for overwriting (just for style, but it’s a good pattern). Four direct transformation rules matching footnote, emphasis, @role attribute of emphasis and blockquote. Grouping key matching “inline” para‘s children: the generate id of first preceding “block” element or para parent. Grouping rule for para applying templates to self and “block” elements in "group" mode. Rule matching para in "group" mode (also named makePara): output a paragraph if there is a group with context node generate id as key value. Rule matching any element in "group" mode (it’ll be any “block” element): apply templates to self (“reset” mode) and call makePara named template.

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

Sidebar

Related Questions

I once did a cursory search and found no good CVS bindings for Python.
When you search in Google (i'm almost sure that Altavista did the same thing)
We all know how to use <ctrl>-R to reverse search through history, but did
Did you ever have to choose between WISA or LAMP at the beginning of
Did anyone of you ever find a way of getting the Microsoft Report Viewer
Did you ever had a bug in your code, you could not resolve? I
Did you ever use Oracle auditing features on a production db? How did that
Did Microsoft abandon support for Windows Presentation Foundation (WPF) on Visual Studio 2005? There
Did the recent purchase of MySQL by Sun and the subsequent buggy releases kill
Did you know that : Map<Object,Object> m1 = new HashMap<Object, Object>(); Map<Object,Object> m2 =

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.