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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:38:38+00:00 2026-05-15T01:38:38+00:00

<py:match path=foo> <?python import os href = select(‘@href’).render() SOMEWHERE = … # what file

  • 0
<py:match path="foo">
    <?python
        import os
        href = select('@href').render()
        SOMEWHERE = ...  # what file contained the foo tag?
        path = os.path.abspath(os.path.join(os.path.dirname(SOMEWHERE), href)
        f = file(path,'r')
        # (do something interesting with f)
    ?>
</py:match>
...
<foo href="../path/relative/to/this/template/abcd.xyz"/>

What should go as “somewhere” above? I want that href attribute to be relative to the file with the foo tag in it, like href attributes on other tags.

Alternatively, what file contained the py:match block? This is less good because it may be in a different directory from the file with the foo tag.

Even less good: I could supply the path of the file I’m rendering as a context argument from outside Genshi, but that might be in a different directory from both of the above.

  • 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-15T01:38:39+00:00Added an answer on May 15, 2026 at 1:38 am

    You need to make sure that the driver program (i.e., the Python program that parses the input file) runs in the directory of the file containing the foo tag. Otherwise, you need to pass down the relative path (i.e., how to get from the directory in which the reader runs to the directory of the file being read) as a context argument to your Python code and add it to the os.path.join command.

    With this setup (and using Genshi 0.6 installed on MacOS X 10.6.3 via the Fink package genshi-py26) the command os.getcwd() returns the current working directory of the file containing the foo tag.

    For such complicated path constructs I also strongly recommend to use path=os.path.normpath(path), since you may not want such things to leak in your resulting HTML code.

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

Sidebar

Related Questions

I need some help trying to match a C include file with full path
For example: I know how to match www.domain.com/foo/21 sub foo : Path('/foo') Args(1) {
I was trying out to create a regular expression to match file path in
I'm trying to write a regex to match any path that contains /? to
I have a hierarchical datastructure in Django, and want to match the path to
url1: /dir-images/no1/top-left.gif url2: /test-1/test-2/test I want to match the path before the last slash
I wrote a regular expression that parses a file path into different group (DRIVE,
I have trouble creating a Catalyst action that would match a single file in
The following instance method takes a file path and returns the file's prefix (the
I am trying to match clicked linked path with other links. It does not

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.