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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:26:01+00:00 2026-05-21T05:26:01+00:00

I have a filesystem like XML structure, and now I want to get the

  • 0

I have a filesystem like XML structure, and now I want to get the “filepath” of a . I tried the following XSLT, but it doesn’t work. I only get these errors:

Warning:
XSLTProcessor::transformToXml():
Templates: in
C:\Users\Ludger\Documents\XAMPP\htdocs\CloudAmp\devel\php\localAudioFileLocationScanner.php
on line 60

Warning:
XSLTProcessor::transformToXml(): #0
name //file in
C:\Users\Ludger\Documents\XAMPP\htdocs\CloudAmp\devel\php\localAudioFileLocationScanner.php
on line 60

Warning:
XSLTProcessor::transformToXml(): #1
name //file in
C:\Users\Ludger\Documents\XAMPP\htdocs\CloudAmp\devel\php\localAudioFileLocationScanner.php on line 60

[…]

Warning: XSLTProcessor::transformToXml():
xsltApplyXSLTTemplate: A potential
infinite template recursion was
detected. You can adjust xsltMaxDepth
(–maxdepth) in order to raise the
maximum number of nested template
calls and variables/params (currently
set to 3000). in
C:\Users\Ludger\DocumentsXA
MPP\htdocs\CloudAmp\devel\php\localAudioFileLocationScanner.php
on line 60

XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/dir">
        <xsl:apply-templates select="@name" />
        <xsl:apply-templates select="parent::dir" />
    </xsl:template>

    <xsl:template match="//file">
        <xsl:apply-templates select="@name" />
        <xsl:apply-templates select="parent::dir" />
    </xsl:template>
</xsl:stylesheet>

Source XML:

<root>
  <path val="C:/Users/">
    <file name="a.txt"/>
    <dir name="aaa">
      <file name="b.txt"/>
      <file name="c.txt"/>
    </dir>
    <dir name="bbb">
      <dir name="ccc">
        <file name="d.txt"/>
      </dir>
    </dir>
  </path>
</root>

I can’t get it working. It would be great if you can help me out.

  • 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-21T05:26:02+00:00Added an answer on May 21, 2026 at 5:26 am

    What’s happening is that you’re matching any file element, then applying templates to its parent dir, which is matched by the default template for elements, which applies templates to all of its children, resulting in another match of the same file and starting an infinite recursion.

    (Note that your template for dir elements never matches anything, because it’s looking only for dir elements that are a child of the root node, of which you have none.)

    The following stylesheet:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:template match="dir" mode="path">
            <xsl:value-of select="@name" />
            <xsl:text>/</xsl:text>
        </xsl:template>
        <xsl:template match="file">
            <xsl:apply-templates select="ancestor::dir" mode="path"/>
            <xsl:value-of select="@name" />
        </xsl:template>
    </xsl:stylesheet>
    

    Produces the following output:

    a.txt
    aaa/b.txt
    aaa/c.txt
    bbb/ccc/d.txt
    

    Edit: I think it’s generally better to push forward through the document when backtracking can be avoided. The following stylesheet produces the same output as above, but is more efficient and elegant:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="dir">
            <xsl:param name="prev" select="''" />
            <xsl:apply-templates>
                <xsl:with-param name="prev" select="concat($prev, @name, '/')" />
            </xsl:apply-templates>
        </xsl:template>
        <xsl:template match="file">
            <xsl:param name="prev" select="''" />
            <xsl:value-of select="concat($prev, @name)" />
        </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a XML structure like the following: <Root> <Node Name=File System> <Node Name=C:\Windows\System32\drivers\etc\hosts>
I currently have a filesystem path I would like to index into a SQL
I have a certain boost::filesystem::path in hand and I'd like to append a string
In the filesystem I have /file.aspx /directory/default.aspx I want to configure IIS so that
I have a FAT filesystem mounted in Linux with the vfat driver. I want
I have a question regarding ACLs on a network filesystem. Basically, I want to
I have some files in the same directory (in UNIX filesystem) that looks like:
I have a boost::filesystem::path instance x . I would like to determine whether x
now i have such structure on my server ./site.com/ ./site.com/mage ./site.com/mage/Mage.php ./site.com/mage/app ......... ./site.com/public
I have this kinda interesting requirement. Typically you use XSLT to transform an XML

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.