Universal File Editor for XML/SVG/HTML with XPath and CSS selector support
Project description
xsl - Universal File Editor
๐ ๏ธ Powerful CLI tool and Python library for editing XML, SVG, and HTML files using XPath and CSS selectors.
โจ Features
- ๐ XPath & CSS Selectors - Precise element targeting and querying
- ๐ Multiple Formats - Full support for XML, SVG, and HTML documents
- ๐ Local & Remote Files - Edit files locally or fetch from URLs
- ๐ฆ Data URI Extraction - Extract and decode embedded content (PDFs, images, documents)
- โก Multiple Interfaces - CLI commands, interactive shell, and HTTP server
- ๐ฅ๏ธ Web Interface - Modern browser-based editor with real-time API
- ๐ Python API - Full programmatic access for automation and integration
- ๐ง Extensible - Plugin architecture for custom file processors
๐ Quick Start
Installation
# Basic installation
pip install xsl
# Full installation with all features
pip install xsl[full]
# Specific feature sets
pip install xsl[xpath] # XPath support only
pip install xsl[css] # CSS selectors only
pip install xsl[remote] # Remote file support only
pip install xsl[server] # HTTP server support only
CLI Usage
# Load and query files
xsl load example.svg
xsl query "//svg:text[@id='title']"
xsl set "//svg:text[@id='title']" "New Title"
# Extract embedded data
xsl extract "//svg:image/@xlink:href" --output document.pdf
xsl extract "//svg:image/@xlink:href" --info
# Interactive shell
xsl shell
# HTTP Server
xsl server --port 8082
Python API
from xsl import FileEditor
# Load and edit file
editor = FileEditor('example.svg')
editor.set_element_text("//svg:text[@id='title']", "New Title")
editor.save('modified.svg')
# Extract Data URI
result = editor.extract_data_uri("//svg:image/@xlink:href")
if 'error' not in result:
print(f"Found {result['mime_type']} ({result['size']} bytes)")
# Work with remote files
remote_editor = FileEditor('https://example.com/diagram.svg')
elements = remote_editor.list_elements("//svg:*[@id]")
๐ Documentation
- CLI Reference - Complete command-line interface guide
- Python API - Full API documentation with examples
- Server Guide - HTTP server setup and API reference
- XPath Examples - Common XPath patterns and use cases
- Tutorials - Step-by-step guides for common tasks
๐ฏ Use Cases
๐ Extract Data from SVG Diagrams
# Extract embedded PDF from technical diagram
xsl extract "//svg:image/@xlink:href" --output manual.pdf
# Get chart data from SVG
xsl query "//svg:foreignObject//script[@type='application/json']"
๐ง Batch Update XML Configurations
# Update database connections across config files
for config in configs/*.xml; do
xsl set "//database/host" "new-server.com" "$config"
xsl save "$config"
done
๐ Parse Web Pages for Data
# Extract structured data from HTML
xsl query "//table[@id='data']//tr[@data-status='active']" page.html
xsl extract "//script[@type='application/json']" --output data.json
๐ Document Format Conversion
# Convert XML structure using XPath
from xsl import FileEditor
source = FileEditor('legacy.xml')
data = source.list_elements("//record")
target = FileEditor('template.xml')
for item in data:
target.add_element("//records", "entry", item['text'], item['attributes'])
target.save('migrated.xml')
๐ XPath Examples
SVG Files
# Get all text elements
//svg:text
# Find elements by ID
//svg:*[@id='title']
# Extract Data URIs
//svg:image/@xlink:href[starts-with(., 'data:')]
# Get metadata
//svg:metadata
XML Files
# Find by attribute
//user[@type='admin']
# Text content search
//*[contains(text(), 'error')]
# Nested elements
//config//database//host
HTML Files
# CSS class targeting
//div[@class='content']
# Form elements
//input[@type='checkbox'][@checked]
# JSON script tags
//script[@type='application/json']
๐ HTTP Server API
Start the server:
xsl server --port 8082
Direct Data URI Extraction
# Extract from remote file
curl "http://localhost:8082/api/extract?url=https://example.com/diagram.svg&xpath=//svg:image/@href"
Full API Workflow
# Load file
curl -X POST http://localhost:8082/api/load \
-H "Content-Type: application/json" \
-d '{"file_path": "example.svg"}'
# Query elements
curl -X POST http://localhost:8082/api/query \
-H "Content-Type: application/json" \
-d '{"query": "//svg:text", "type": "xpath"}'
# Update content
curl -X POST http://localhost:8082/api/update \
-H "Content-Type: application/json" \
-d '{"xpath": "//svg:text[@id=\"title\"]", "type": "text", "value": "Updated"}'
# Save changes
curl -X POST http://localhost:8082/api/save \
-H "Content-Type: application/json" \
-d '{"output_path": "modified.svg"}'
Web Interface
Open http://localhost:8082 in your browser for a full-featured web interface with:
- ๐ File Management - Load local files or remote URLs
- ๐ Interactive Queries - Test XPath and CSS selectors with real-time results
- โ๏ธ Visual Editing - Modify elements through web forms
- ๐ฆ Data Extraction - Extract and download embedded resources
- ๐ Element Browser - Navigate document structure visually
๐งช Examples and Testing
Generate example files:
xsl examples --dir ./test_files
This creates:
example.svg- SVG with embedded Data URIs and metadataexample.xml- XML database with users and file dataexample.html- HTML with embedded SVG and JSONUSAGE_EXAMPLES.md- Comprehensive usage guide
โ๏ธ Configuration
Optional Dependencies
xsl works with basic XML support out of the box, but optional dependencies unlock additional features:
lxml- Required for XPath queries and advanced XML processingbeautifulsoup4- Enables CSS selectors for HTML filesrequests- Allows loading files from remote URLs
Install all features:
pip install xsl[full]
Environment Variables
# Default server settings
export xsl_DEFAULT_PORT=8082
export xsl_DEFAULT_HOST=localhost
# Debug mode
export xsl_DEBUG=1
๐ง Development
Setup Development Environment
git clone https://github.com/veridock/xsl.git
cd xsl
# Install Poetry
curl -sSL https://install.python-poetry.org | python3 -
# Install dependencies
poetry install --extras "full"
# Run tests
poetry run pytest
# Format code
poetry run black xsl/
poetry run isort xsl/
Running Tests
# All tests
poetry run pytest
# With coverage
poetry run pytest --cov=xsl --cov-report=html
# Specific test categories
poetry run pytest -m "not slow" # Skip slow tests
poetry run pytest -m "integration" # Only integration tests
Code Quality
# Format and lint
poetry run black xsl/ tests/
poetry run isort xsl/ tests/
poetry run flake8 xsl/ tests/
poetry run mypy xsl/
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Quick Contribution Workflow
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Run tests:
poetry run pytest - Format code:
poetry run black xsl/ - Commit:
git commit -m 'Add amazing feature' - Push:
git push origin feature/amazing-feature - Open a Pull Request
๐ Requirements
- Python 3.8+
- Optional: lxml, beautifulsoup4, requests (install with
[full]extra)
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built with lxml for robust XML processing
- Uses Beautiful Soup for HTML parsing
- Powered by Poetry for dependency management
๐ Support
- ๐ Documentation: GitHub Wiki
- ๐ Bug Reports: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ง Email: contact@veridock.com
Made with โค๏ธ by the xsl team
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xsl-0.1.8.tar.gz.
File metadata
- Download URL: xsl-0.1.8.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.15.3-200.fc42.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30e58420e11e287c5939af3a70fed84fca68cb73fb7ac9d68ad0d8a68988c438
|
|
| MD5 |
f9cc3af46f06a901da033a415476c84e
|
|
| BLAKE2b-256 |
c32d60e8f6de69dbacb692d3aee14bcd379b71f3192fef44be86c3424bd0baca
|
File details
Details for the file xsl-0.1.8-py3-none-any.whl.
File metadata
- Download URL: xsl-0.1.8-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.15.3-200.fc42.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47585cb0da2f7464e8a4df670288a1ec3990839fe0c1a70419b2c73359302e32
|
|
| MD5 |
0431c05a6bf52e62f1c59884b1a65188
|
|
| BLAKE2b-256 |
5e578c2bc42cf80b4d9de624aec3b6cdb7e3a2a3205ae91a5035e95e126f0a3d
|