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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:22:08+00:00 2026-06-18T02:22:08+00:00

I am refactoring an xslt for word xml to improve performance as recommended here

  • 0

I am refactoring an xslt for word xml to improve performance as recommended here. I am relatively new to xslt. Why are the following statements not equivalent?

Form1

<xsl:value-of select="//w:style[@w:styleId = $styleName][ancestor::pkg:part/@pkg:name='/word/styles.xml']"/> 

Form2

<xsl:value-of select="/pkg:package/pkg:part[@pkg:name='/word/styles.xml']/child::w:style[@w:styleId = $styleName]" />

Note that pkg:package is the root and pkg:part are direct children.

Form1 states that get the w:style element with the attribute equaling $styleName, whose ancestors are pkg:part with attribute @pkg:name='/word/styles.xml'.

Form 2 states that get the w:style elements with the attributes equaling $styleName who are children of pkg:package/pkg:par@pkg:name='/word/styles.xml'

The actual statement I am trying to rewrite is this one:

<xsl:value-of select="//w:style[@w:styleId = $styleName][ancestor::pkg:part/@pkg:name='/word/styles.xml']/w:pPr/w:numPr/w:numId/@w:val"/>

Thank you.

  • 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-18T02:22:09+00:00Added an answer on June 18, 2026 at 2:22 am

    Your second XPath is on the right track, but it would only match w:styles that are direct children of pkg:part (the child:: axis is redundant here), which I don’t think they are. This should work:

    /pkg:package/pkg:part[@pkg:name='/word/styles.xml']//w:style[@w:styleId = $styleName]
    

    and I think this is an improvement over the original XPath, but it still has a // in it. My knowledge of wordprocessingML is not very extensive, but is it the case that all <w:style>s are the children of <w:styles> elements, which are all children of a <pkg:xmlData> element? If so, this should work (split across 2 lines for readability):

    /pkg:package/pkg:part[@pkg:name='/word/styles.xml']
                                   /pkg:xmlData/w:styles/w:style[@w:styleId = $styleName]
    

    One other possibility for improving performance is to use a key. In your XSLT, you would define a key like this:

    <xsl:key name="kStyle" match="w:style" use="@w:styleId" />
    

    And then you would access the style you want like this:

    <xsl:value-of select="key('kStyle', $styleName)
                                   [ancestor::pkg:part/@pkg:name = '/word/styles.xml']
                                   /w:pPr/w:numPr/w:numId/@w:val" />
    

    Key lookups are generally very efficient, so this second option may be the better one in terms of performance.

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

Sidebar

Related Questions

I am currently refactoring my project and one thing I'm not quite sure on
I am refactoring some code that I did not write, and I found a
I'm refactoring a class and adding a new dependency to it. The class is
I'm refactoring about 600 lines of javascript into the module pattern. Here is a
Whilst refactoring code I changed the all the if not null conditions to follow
I'm exploring the XML -> XSLT -> HTML meme for producing web content. I
When refactoring away some #defines I came across declarations similar to the following in
Refactoring old code, I want to change the following method: - (id)initWithFrame:(CGRect)frame { //
While refactoring my code base I found a piece of code which I'd like
What refactoring tools similar to Visual Studio / DevExpress / Resharper are available for

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.