
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
๐ ๏ธ Powerful CLI tool and Python library for editing XML, SVG, and HTML files using XPath and CSS selectors.
# 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
# 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
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]")
# 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']"
# Update database connections across config files
for config in configs/*.xml; do
xsl set "//database/host" "new-server.com" "$config"
xsl save "$config"
done
# 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
# 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')
# 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
# Find by attribute
//user[@type='admin']
# Text content search
//*[contains(text(), 'error')]
# Nested elements
//config//database//host
# CSS class targeting
//div[@class='content']
# Form elements
//input[@type='checkbox'][@checked]
# JSON script tags
//script[@type='application/json']
Start the server:
xsl server --port 8082
# Extract from remote file
curl "http://localhost:8082/api/extract?url=https://example.com/diagram.svg&xpath=//svg:image/@href"
# 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"}'
Open http://localhost:8082
in your browser for a full-featured web interface with:
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 guidexsl 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 URLsInstall all features:
pip install xsl[full]
# Default server settings
export xsl_DEFAULT_PORT=8082
export xsl_DEFAULT_HOST=localhost
# Debug mode
export xsl_DEBUG=1
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/
# 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
# Format and lint
poetry run black xsl/ tests/
poetry run isort xsl/ tests/
poetry run flake8 xsl/ tests/
poetry run mypy xsl/
We welcome contributions! Please see our Contributing Guide for details.
git checkout -b feature/amazing-feature
poetry run pytest
poetry run black xsl/
git commit -m 'Add amazing feature'
git push origin feature/amazing-feature
[full]
extra)This project is licensed under the MIT License - see the LICENSE file for details.
Made with โค๏ธ by the xsl team
FAQs
Universal File Editor for XML/SVG/HTML with XPath and CSS selector support
We found that xsl demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600ร faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.