xsl 0.1.6__tar.gz → 0.1.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xsl-0.1.9/PKG-INFO +372 -0
- xsl-0.1.9/README.md +338 -0
- {xsl-0.1.6 → xsl-0.1.9}/pyproject.toml +4 -2
- xsl-0.1.9/xsl/__init__.py +19 -0
- xsl-0.1.9/xsl/__main__.py +15 -0
- xsl-0.1.9/xsl/cli.py +471 -0
- xsl-0.1.9/xsl/editor.py +491 -0
- xsl-0.1.9/xsl/server.py +167 -0
- xsl-0.1.9/xsl/utils.py +106 -0
- xsl-0.1.6/PKG-INFO +0 -548
- xsl-0.1.6/README.md +0 -513
- xsl-0.1.6/xsl/__init__.py +0 -1
- xsl-0.1.6/xsl/cli.py +0 -1237
- xsl-0.1.6/xsl/editor.py +0 -5
- xsl-0.1.6/xsl/server.py +0 -5
- xsl-0.1.6/xsl/utils.py +0 -5
- {xsl-0.1.6 → xsl-0.1.9}/LICENSE +0 -0
xsl-0.1.9/PKG-INFO
ADDED
@@ -0,0 +1,372 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: xsl
|
3
|
+
Version: 0.1.9
|
4
|
+
Summary: Universal File Editor for XML/SVG/HTML with XPath and CSS selector support
|
5
|
+
License: Apache-2.0
|
6
|
+
Keywords: xml,svg,html,xpath,editor,cli
|
7
|
+
Author: Tom Sapletta
|
8
|
+
Author-email: info@softreck.dev
|
9
|
+
Requires-Python: >=3.8.1,<4.0
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
11
|
+
Classifier: Intended Audience :: Developers
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
21
|
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
22
|
+
Classifier: Topic :: Text Processing :: Markup :: XML
|
23
|
+
Provides-Extra: css
|
24
|
+
Provides-Extra: full
|
25
|
+
Provides-Extra: remote
|
26
|
+
Provides-Extra: xpath
|
27
|
+
Requires-Dist: beautifulsoup4 (>=4.11.0,<5.0.0) ; extra == "full" or extra == "css"
|
28
|
+
Requires-Dist: lxml (>=4.9.0,<5.0.0) ; extra == "full" or extra == "xpath"
|
29
|
+
Requires-Dist: requests (>=2.28.0,<3.0.0) ; extra == "full" or extra == "remote"
|
30
|
+
Project-URL: Documentation, https://github.com/veridock/xsl/docs
|
31
|
+
Project-URL: Homepage, https://github.com/veridock/xsl
|
32
|
+
Project-URL: Repository, https://github.com/veridock/xsl
|
33
|
+
Description-Content-Type: text/markdown
|
34
|
+
|
35
|
+
# xsl - Universal File Editor
|
36
|
+
|
37
|
+
[](https://badge.fury.io/py/xsl)
|
38
|
+
[](https://pypi.org/project/xsl/)
|
39
|
+
[](https://opensource.org/licenses/MIT)
|
40
|
+
[](https://github.com/veridock/xsl/actions)
|
41
|
+
|
42
|
+
🛠️ **Powerful CLI tool and Python library for editing XML, SVG, and HTML files using XPath and CSS selectors.**
|
43
|
+
|
44
|
+
## ✨ Features
|
45
|
+
|
46
|
+
- **🔍 XPath & CSS Selectors** - Precise element targeting and querying
|
47
|
+
- **📁 Multiple Formats** - Full support for XML, SVG, and HTML documents
|
48
|
+
- **🌐 Local & Remote Files** - Edit files locally or fetch from URLs
|
49
|
+
- **📦 Data URI Extraction** - Extract and decode embedded content (PDFs, images, documents)
|
50
|
+
- **⚡ Multiple Interfaces** - CLI commands, interactive shell, and HTTP server
|
51
|
+
- **🖥️ Web Interface** - Modern browser-based editor with real-time API
|
52
|
+
- **🐍 Python API** - Full programmatic access for automation and integration
|
53
|
+
- **🔧 Extensible** - Plugin architecture for custom file processors
|
54
|
+
|
55
|
+
## 🚀 Quick Start
|
56
|
+
|
57
|
+
### Installation
|
58
|
+
|
59
|
+
```bash
|
60
|
+
# Basic installation
|
61
|
+
pip install xsl
|
62
|
+
|
63
|
+
# Full installation with all features
|
64
|
+
pip install xsl[full]
|
65
|
+
|
66
|
+
# Specific feature sets
|
67
|
+
pip install xsl[xpath] # XPath support only
|
68
|
+
pip install xsl[css] # CSS selectors only
|
69
|
+
pip install xsl[remote] # Remote file support only
|
70
|
+
pip install xsl[server] # HTTP server support only
|
71
|
+
```
|
72
|
+
|
73
|
+
### CLI Usage
|
74
|
+
|
75
|
+
```bash
|
76
|
+
# Load and query files
|
77
|
+
xsl load example.svg
|
78
|
+
xsl query "//svg:text[@id='title']"
|
79
|
+
xsl set "//svg:text[@id='title']" "New Title"
|
80
|
+
|
81
|
+
# Extract embedded data
|
82
|
+
xsl extract "//svg:image/@xlink:href" --output document.pdf
|
83
|
+
xsl extract "//svg:image/@xlink:href" --info
|
84
|
+
|
85
|
+
# Interactive shell
|
86
|
+
xsl shell
|
87
|
+
|
88
|
+
# HTTP Server
|
89
|
+
xsl server --port 8082
|
90
|
+
```
|
91
|
+
|
92
|
+
### Python API
|
93
|
+
|
94
|
+
```python
|
95
|
+
from xsl import FileEditor
|
96
|
+
|
97
|
+
# Load and edit file
|
98
|
+
editor = FileEditor('example.svg')
|
99
|
+
editor.set_element_text("//svg:text[@id='title']", "New Title")
|
100
|
+
editor.save('modified.svg')
|
101
|
+
|
102
|
+
# Extract Data URI
|
103
|
+
result = editor.extract_data_uri("//svg:image/@xlink:href")
|
104
|
+
if 'error' not in result:
|
105
|
+
print(f"Found {result['mime_type']} ({result['size']} bytes)")
|
106
|
+
|
107
|
+
# Work with remote files
|
108
|
+
remote_editor = FileEditor('https://example.com/diagram.svg')
|
109
|
+
elements = remote_editor.list_elements("//svg:*[@id]")
|
110
|
+
```
|
111
|
+
|
112
|
+
## 📖 Documentation
|
113
|
+
|
114
|
+
- **[CLI Reference](docs/cli.md)** - Complete command-line interface guide
|
115
|
+
- **[Python API](docs/api.md)** - Full API documentation with examples
|
116
|
+
- **[Server Guide](docs/server.md)** - HTTP server setup and API reference
|
117
|
+
- **[XPath Examples](docs/xpath.md)** - Common XPath patterns and use cases
|
118
|
+
- **[Tutorials](docs/tutorials/)** - Step-by-step guides for common tasks
|
119
|
+
|
120
|
+
## 🎯 Use Cases
|
121
|
+
|
122
|
+
### 📊 **Extract Data from SVG Diagrams**
|
123
|
+
```bash
|
124
|
+
# Extract embedded PDF from technical diagram
|
125
|
+
xsl extract "//svg:image/@xlink:href" --output manual.pdf
|
126
|
+
|
127
|
+
# Get chart data from SVG
|
128
|
+
xsl query "//svg:foreignObject//script[@type='application/json']"
|
129
|
+
```
|
130
|
+
|
131
|
+
### 🔧 **Batch Update XML Configurations**
|
132
|
+
```bash
|
133
|
+
# Update database connections across config files
|
134
|
+
for config in configs/*.xml; do
|
135
|
+
xsl set "//database/host" "new-server.com" "$config"
|
136
|
+
xsl save "$config"
|
137
|
+
done
|
138
|
+
```
|
139
|
+
|
140
|
+
### 🌐 **Parse Web Pages for Data**
|
141
|
+
```bash
|
142
|
+
# Extract structured data from HTML
|
143
|
+
xsl query "//table[@id='data']//tr[@data-status='active']" page.html
|
144
|
+
xsl extract "//script[@type='application/json']" --output data.json
|
145
|
+
```
|
146
|
+
|
147
|
+
### 🔄 **Document Format Conversion**
|
148
|
+
```python
|
149
|
+
# Convert XML structure using XPath
|
150
|
+
from xsl import FileEditor
|
151
|
+
|
152
|
+
source = FileEditor('legacy.xml')
|
153
|
+
data = source.list_elements("//record")
|
154
|
+
|
155
|
+
target = FileEditor('template.xml')
|
156
|
+
for item in data:
|
157
|
+
target.add_element("//records", "entry", item['text'], item['attributes'])
|
158
|
+
target.save('migrated.xml')
|
159
|
+
```
|
160
|
+
|
161
|
+
## 🔍 XPath Examples
|
162
|
+
|
163
|
+
### SVG Files
|
164
|
+
```bash
|
165
|
+
# Get all text elements
|
166
|
+
//svg:text
|
167
|
+
|
168
|
+
# Find elements by ID
|
169
|
+
//svg:*[@id='title']
|
170
|
+
|
171
|
+
# Extract Data URIs
|
172
|
+
//svg:image/@xlink:href[starts-with(., 'data:')]
|
173
|
+
|
174
|
+
# Get metadata
|
175
|
+
//svg:metadata
|
176
|
+
```
|
177
|
+
|
178
|
+
### XML Files
|
179
|
+
```bash
|
180
|
+
# Find by attribute
|
181
|
+
//user[@type='admin']
|
182
|
+
|
183
|
+
# Text content search
|
184
|
+
//*[contains(text(), 'error')]
|
185
|
+
|
186
|
+
# Nested elements
|
187
|
+
//config//database//host
|
188
|
+
```
|
189
|
+
|
190
|
+
### HTML Files
|
191
|
+
```bash
|
192
|
+
# CSS class targeting
|
193
|
+
//div[@class='content']
|
194
|
+
|
195
|
+
# Form elements
|
196
|
+
//input[@type='checkbox'][@checked]
|
197
|
+
|
198
|
+
# JSON script tags
|
199
|
+
//script[@type='application/json']
|
200
|
+
```
|
201
|
+
|
202
|
+
## 🌐 HTTP Server API
|
203
|
+
|
204
|
+
Start the server:
|
205
|
+
```bash
|
206
|
+
xsl server --port 8082
|
207
|
+
```
|
208
|
+
|
209
|
+
### Direct Data URI Extraction
|
210
|
+
```bash
|
211
|
+
# Extract from remote file
|
212
|
+
curl "http://localhost:8082/api/extract?url=https://example.com/diagram.svg&xpath=//svg:image/@href"
|
213
|
+
```
|
214
|
+
|
215
|
+
### Full API Workflow
|
216
|
+
```bash
|
217
|
+
# Load file
|
218
|
+
curl -X POST http://localhost:8082/api/load \
|
219
|
+
-H "Content-Type: application/json" \
|
220
|
+
-d '{"file_path": "example.svg"}'
|
221
|
+
|
222
|
+
# Query elements
|
223
|
+
curl -X POST http://localhost:8082/api/query \
|
224
|
+
-H "Content-Type: application/json" \
|
225
|
+
-d '{"query": "//svg:text", "type": "xpath"}'
|
226
|
+
|
227
|
+
# Update content
|
228
|
+
curl -X POST http://localhost:8082/api/update \
|
229
|
+
-H "Content-Type: application/json" \
|
230
|
+
-d '{"xpath": "//svg:text[@id=\"title\"]", "type": "text", "value": "Updated"}'
|
231
|
+
|
232
|
+
# Save changes
|
233
|
+
curl -X POST http://localhost:8082/api/save \
|
234
|
+
-H "Content-Type: application/json" \
|
235
|
+
-d '{"output_path": "modified.svg"}'
|
236
|
+
```
|
237
|
+
|
238
|
+
### Web Interface
|
239
|
+
|
240
|
+
Open `http://localhost:8082` in your browser for a full-featured web interface with:
|
241
|
+
|
242
|
+
- 📁 **File Management** - Load local files or remote URLs
|
243
|
+
- 🔍 **Interactive Queries** - Test XPath and CSS selectors with real-time results
|
244
|
+
- ✏️ **Visual Editing** - Modify elements through web forms
|
245
|
+
- 📦 **Data Extraction** - Extract and download embedded resources
|
246
|
+
- 📊 **Element Browser** - Navigate document structure visually
|
247
|
+
|
248
|
+
## 🧪 Examples and Testing
|
249
|
+
|
250
|
+
Generate example files:
|
251
|
+
```bash
|
252
|
+
xsl examples --dir ./test_files
|
253
|
+
```
|
254
|
+
|
255
|
+
This creates:
|
256
|
+
- `example.svg` - SVG with embedded Data URIs and metadata
|
257
|
+
- `example.xml` - XML database with users and file data
|
258
|
+
- `example.html` - HTML with embedded SVG and JSON
|
259
|
+
- `USAGE_EXAMPLES.md` - Comprehensive usage guide
|
260
|
+
|
261
|
+
## ⚙️ Configuration
|
262
|
+
|
263
|
+
### Optional Dependencies
|
264
|
+
|
265
|
+
xsl works with basic XML support out of the box, but optional dependencies unlock additional features:
|
266
|
+
|
267
|
+
- **`lxml`** - Required for XPath queries and advanced XML processing
|
268
|
+
- **`beautifulsoup4`** - Enables CSS selectors for HTML files
|
269
|
+
- **`requests`** - Allows loading files from remote URLs
|
270
|
+
|
271
|
+
Install all features:
|
272
|
+
```bash
|
273
|
+
pip install xsl[full]
|
274
|
+
```
|
275
|
+
|
276
|
+
### Environment Variables
|
277
|
+
|
278
|
+
```bash
|
279
|
+
# Default server settings
|
280
|
+
export xsl_DEFAULT_PORT=8082
|
281
|
+
export xsl_DEFAULT_HOST=localhost
|
282
|
+
|
283
|
+
# Debug mode
|
284
|
+
export xsl_DEBUG=1
|
285
|
+
```
|
286
|
+
|
287
|
+
## 🔧 Development
|
288
|
+
|
289
|
+
### Setup Development Environment
|
290
|
+
|
291
|
+
```bash
|
292
|
+
git clone https://github.com/veridock/xsl.git
|
293
|
+
cd xsl
|
294
|
+
|
295
|
+
# Install Poetry
|
296
|
+
curl -sSL https://install.python-poetry.org | python3 -
|
297
|
+
|
298
|
+
# Install dependencies
|
299
|
+
poetry install --extras "full"
|
300
|
+
|
301
|
+
# Run tests
|
302
|
+
poetry run pytest
|
303
|
+
|
304
|
+
# Format code
|
305
|
+
poetry run black xsl/
|
306
|
+
poetry run isort xsl/
|
307
|
+
```
|
308
|
+
|
309
|
+
### Running Tests
|
310
|
+
|
311
|
+
```bash
|
312
|
+
# All tests
|
313
|
+
poetry run pytest
|
314
|
+
|
315
|
+
# With coverage
|
316
|
+
poetry run pytest --cov=xsl --cov-report=html
|
317
|
+
|
318
|
+
# Specific test categories
|
319
|
+
poetry run pytest -m "not slow" # Skip slow tests
|
320
|
+
poetry run pytest -m "integration" # Only integration tests
|
321
|
+
```
|
322
|
+
|
323
|
+
### Code Quality
|
324
|
+
|
325
|
+
```bash
|
326
|
+
# Format and lint
|
327
|
+
poetry run black xsl/ tests/
|
328
|
+
poetry run isort xsl/ tests/
|
329
|
+
poetry run flake8 xsl/ tests/
|
330
|
+
poetry run mypy xsl/
|
331
|
+
```
|
332
|
+
|
333
|
+
## 🤝 Contributing
|
334
|
+
|
335
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
336
|
+
|
337
|
+
### Quick Contribution Workflow
|
338
|
+
|
339
|
+
1. Fork the repository
|
340
|
+
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
341
|
+
3. Make your changes and add tests
|
342
|
+
4. Run tests: `poetry run pytest`
|
343
|
+
5. Format code: `poetry run black xsl/`
|
344
|
+
6. Commit: `git commit -m 'Add amazing feature'`
|
345
|
+
7. Push: `git push origin feature/amazing-feature`
|
346
|
+
8. Open a Pull Request
|
347
|
+
|
348
|
+
## 📋 Requirements
|
349
|
+
|
350
|
+
- **Python 3.8+**
|
351
|
+
- **Optional:** lxml, beautifulsoup4, requests (install with `[full]` extra)
|
352
|
+
|
353
|
+
## 📄 License
|
354
|
+
|
355
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
356
|
+
|
357
|
+
## 🙏 Acknowledgments
|
358
|
+
|
359
|
+
- Built with [lxml](https://lxml.de/) for robust XML processing
|
360
|
+
- Uses [Beautiful Soup](https://www.crummy.com/software/BeautifulSoup/) for HTML parsing
|
361
|
+
- Powered by [Poetry](https://python-poetry.org/) for dependency management
|
362
|
+
|
363
|
+
## 📞 Support
|
364
|
+
|
365
|
+
- 📖 **Documentation:** [GitHub Wiki](https://github.com/veridock/xsl/wiki)
|
366
|
+
- 🐛 **Bug Reports:** [GitHub Issues](https://github.com/veridock/xsl/issues)
|
367
|
+
- 💬 **Discussions:** [GitHub Discussions](https://github.com/veridock/xsl/discussions)
|
368
|
+
- 📧 **Email:** contact@veridock.com
|
369
|
+
|
370
|
+
---
|
371
|
+
|
372
|
+
**Made with ❤️ by the xsl team**
|
xsl-0.1.9/README.md
ADDED
@@ -0,0 +1,338 @@
|
|
1
|
+
# xsl - Universal File Editor
|
2
|
+
|
3
|
+
[](https://badge.fury.io/py/xsl)
|
4
|
+
[](https://pypi.org/project/xsl/)
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
6
|
+
[](https://github.com/veridock/xsl/actions)
|
7
|
+
|
8
|
+
🛠️ **Powerful CLI tool and Python library for editing XML, SVG, and HTML files using XPath and CSS selectors.**
|
9
|
+
|
10
|
+
## ✨ Features
|
11
|
+
|
12
|
+
- **🔍 XPath & CSS Selectors** - Precise element targeting and querying
|
13
|
+
- **📁 Multiple Formats** - Full support for XML, SVG, and HTML documents
|
14
|
+
- **🌐 Local & Remote Files** - Edit files locally or fetch from URLs
|
15
|
+
- **📦 Data URI Extraction** - Extract and decode embedded content (PDFs, images, documents)
|
16
|
+
- **⚡ Multiple Interfaces** - CLI commands, interactive shell, and HTTP server
|
17
|
+
- **🖥️ Web Interface** - Modern browser-based editor with real-time API
|
18
|
+
- **🐍 Python API** - Full programmatic access for automation and integration
|
19
|
+
- **🔧 Extensible** - Plugin architecture for custom file processors
|
20
|
+
|
21
|
+
## 🚀 Quick Start
|
22
|
+
|
23
|
+
### Installation
|
24
|
+
|
25
|
+
```bash
|
26
|
+
# Basic installation
|
27
|
+
pip install xsl
|
28
|
+
|
29
|
+
# Full installation with all features
|
30
|
+
pip install xsl[full]
|
31
|
+
|
32
|
+
# Specific feature sets
|
33
|
+
pip install xsl[xpath] # XPath support only
|
34
|
+
pip install xsl[css] # CSS selectors only
|
35
|
+
pip install xsl[remote] # Remote file support only
|
36
|
+
pip install xsl[server] # HTTP server support only
|
37
|
+
```
|
38
|
+
|
39
|
+
### CLI Usage
|
40
|
+
|
41
|
+
```bash
|
42
|
+
# Load and query files
|
43
|
+
xsl load example.svg
|
44
|
+
xsl query "//svg:text[@id='title']"
|
45
|
+
xsl set "//svg:text[@id='title']" "New Title"
|
46
|
+
|
47
|
+
# Extract embedded data
|
48
|
+
xsl extract "//svg:image/@xlink:href" --output document.pdf
|
49
|
+
xsl extract "//svg:image/@xlink:href" --info
|
50
|
+
|
51
|
+
# Interactive shell
|
52
|
+
xsl shell
|
53
|
+
|
54
|
+
# HTTP Server
|
55
|
+
xsl server --port 8082
|
56
|
+
```
|
57
|
+
|
58
|
+
### Python API
|
59
|
+
|
60
|
+
```python
|
61
|
+
from xsl import FileEditor
|
62
|
+
|
63
|
+
# Load and edit file
|
64
|
+
editor = FileEditor('example.svg')
|
65
|
+
editor.set_element_text("//svg:text[@id='title']", "New Title")
|
66
|
+
editor.save('modified.svg')
|
67
|
+
|
68
|
+
# Extract Data URI
|
69
|
+
result = editor.extract_data_uri("//svg:image/@xlink:href")
|
70
|
+
if 'error' not in result:
|
71
|
+
print(f"Found {result['mime_type']} ({result['size']} bytes)")
|
72
|
+
|
73
|
+
# Work with remote files
|
74
|
+
remote_editor = FileEditor('https://example.com/diagram.svg')
|
75
|
+
elements = remote_editor.list_elements("//svg:*[@id]")
|
76
|
+
```
|
77
|
+
|
78
|
+
## 📖 Documentation
|
79
|
+
|
80
|
+
- **[CLI Reference](docs/cli.md)** - Complete command-line interface guide
|
81
|
+
- **[Python API](docs/api.md)** - Full API documentation with examples
|
82
|
+
- **[Server Guide](docs/server.md)** - HTTP server setup and API reference
|
83
|
+
- **[XPath Examples](docs/xpath.md)** - Common XPath patterns and use cases
|
84
|
+
- **[Tutorials](docs/tutorials/)** - Step-by-step guides for common tasks
|
85
|
+
|
86
|
+
## 🎯 Use Cases
|
87
|
+
|
88
|
+
### 📊 **Extract Data from SVG Diagrams**
|
89
|
+
```bash
|
90
|
+
# Extract embedded PDF from technical diagram
|
91
|
+
xsl extract "//svg:image/@xlink:href" --output manual.pdf
|
92
|
+
|
93
|
+
# Get chart data from SVG
|
94
|
+
xsl query "//svg:foreignObject//script[@type='application/json']"
|
95
|
+
```
|
96
|
+
|
97
|
+
### 🔧 **Batch Update XML Configurations**
|
98
|
+
```bash
|
99
|
+
# Update database connections across config files
|
100
|
+
for config in configs/*.xml; do
|
101
|
+
xsl set "//database/host" "new-server.com" "$config"
|
102
|
+
xsl save "$config"
|
103
|
+
done
|
104
|
+
```
|
105
|
+
|
106
|
+
### 🌐 **Parse Web Pages for Data**
|
107
|
+
```bash
|
108
|
+
# Extract structured data from HTML
|
109
|
+
xsl query "//table[@id='data']//tr[@data-status='active']" page.html
|
110
|
+
xsl extract "//script[@type='application/json']" --output data.json
|
111
|
+
```
|
112
|
+
|
113
|
+
### 🔄 **Document Format Conversion**
|
114
|
+
```python
|
115
|
+
# Convert XML structure using XPath
|
116
|
+
from xsl import FileEditor
|
117
|
+
|
118
|
+
source = FileEditor('legacy.xml')
|
119
|
+
data = source.list_elements("//record")
|
120
|
+
|
121
|
+
target = FileEditor('template.xml')
|
122
|
+
for item in data:
|
123
|
+
target.add_element("//records", "entry", item['text'], item['attributes'])
|
124
|
+
target.save('migrated.xml')
|
125
|
+
```
|
126
|
+
|
127
|
+
## 🔍 XPath Examples
|
128
|
+
|
129
|
+
### SVG Files
|
130
|
+
```bash
|
131
|
+
# Get all text elements
|
132
|
+
//svg:text
|
133
|
+
|
134
|
+
# Find elements by ID
|
135
|
+
//svg:*[@id='title']
|
136
|
+
|
137
|
+
# Extract Data URIs
|
138
|
+
//svg:image/@xlink:href[starts-with(., 'data:')]
|
139
|
+
|
140
|
+
# Get metadata
|
141
|
+
//svg:metadata
|
142
|
+
```
|
143
|
+
|
144
|
+
### XML Files
|
145
|
+
```bash
|
146
|
+
# Find by attribute
|
147
|
+
//user[@type='admin']
|
148
|
+
|
149
|
+
# Text content search
|
150
|
+
//*[contains(text(), 'error')]
|
151
|
+
|
152
|
+
# Nested elements
|
153
|
+
//config//database//host
|
154
|
+
```
|
155
|
+
|
156
|
+
### HTML Files
|
157
|
+
```bash
|
158
|
+
# CSS class targeting
|
159
|
+
//div[@class='content']
|
160
|
+
|
161
|
+
# Form elements
|
162
|
+
//input[@type='checkbox'][@checked]
|
163
|
+
|
164
|
+
# JSON script tags
|
165
|
+
//script[@type='application/json']
|
166
|
+
```
|
167
|
+
|
168
|
+
## 🌐 HTTP Server API
|
169
|
+
|
170
|
+
Start the server:
|
171
|
+
```bash
|
172
|
+
xsl server --port 8082
|
173
|
+
```
|
174
|
+
|
175
|
+
### Direct Data URI Extraction
|
176
|
+
```bash
|
177
|
+
# Extract from remote file
|
178
|
+
curl "http://localhost:8082/api/extract?url=https://example.com/diagram.svg&xpath=//svg:image/@href"
|
179
|
+
```
|
180
|
+
|
181
|
+
### Full API Workflow
|
182
|
+
```bash
|
183
|
+
# Load file
|
184
|
+
curl -X POST http://localhost:8082/api/load \
|
185
|
+
-H "Content-Type: application/json" \
|
186
|
+
-d '{"file_path": "example.svg"}'
|
187
|
+
|
188
|
+
# Query elements
|
189
|
+
curl -X POST http://localhost:8082/api/query \
|
190
|
+
-H "Content-Type: application/json" \
|
191
|
+
-d '{"query": "//svg:text", "type": "xpath"}'
|
192
|
+
|
193
|
+
# Update content
|
194
|
+
curl -X POST http://localhost:8082/api/update \
|
195
|
+
-H "Content-Type: application/json" \
|
196
|
+
-d '{"xpath": "//svg:text[@id=\"title\"]", "type": "text", "value": "Updated"}'
|
197
|
+
|
198
|
+
# Save changes
|
199
|
+
curl -X POST http://localhost:8082/api/save \
|
200
|
+
-H "Content-Type: application/json" \
|
201
|
+
-d '{"output_path": "modified.svg"}'
|
202
|
+
```
|
203
|
+
|
204
|
+
### Web Interface
|
205
|
+
|
206
|
+
Open `http://localhost:8082` in your browser for a full-featured web interface with:
|
207
|
+
|
208
|
+
- 📁 **File Management** - Load local files or remote URLs
|
209
|
+
- 🔍 **Interactive Queries** - Test XPath and CSS selectors with real-time results
|
210
|
+
- ✏️ **Visual Editing** - Modify elements through web forms
|
211
|
+
- 📦 **Data Extraction** - Extract and download embedded resources
|
212
|
+
- 📊 **Element Browser** - Navigate document structure visually
|
213
|
+
|
214
|
+
## 🧪 Examples and Testing
|
215
|
+
|
216
|
+
Generate example files:
|
217
|
+
```bash
|
218
|
+
xsl examples --dir ./test_files
|
219
|
+
```
|
220
|
+
|
221
|
+
This creates:
|
222
|
+
- `example.svg` - SVG with embedded Data URIs and metadata
|
223
|
+
- `example.xml` - XML database with users and file data
|
224
|
+
- `example.html` - HTML with embedded SVG and JSON
|
225
|
+
- `USAGE_EXAMPLES.md` - Comprehensive usage guide
|
226
|
+
|
227
|
+
## ⚙️ Configuration
|
228
|
+
|
229
|
+
### Optional Dependencies
|
230
|
+
|
231
|
+
xsl works with basic XML support out of the box, but optional dependencies unlock additional features:
|
232
|
+
|
233
|
+
- **`lxml`** - Required for XPath queries and advanced XML processing
|
234
|
+
- **`beautifulsoup4`** - Enables CSS selectors for HTML files
|
235
|
+
- **`requests`** - Allows loading files from remote URLs
|
236
|
+
|
237
|
+
Install all features:
|
238
|
+
```bash
|
239
|
+
pip install xsl[full]
|
240
|
+
```
|
241
|
+
|
242
|
+
### Environment Variables
|
243
|
+
|
244
|
+
```bash
|
245
|
+
# Default server settings
|
246
|
+
export xsl_DEFAULT_PORT=8082
|
247
|
+
export xsl_DEFAULT_HOST=localhost
|
248
|
+
|
249
|
+
# Debug mode
|
250
|
+
export xsl_DEBUG=1
|
251
|
+
```
|
252
|
+
|
253
|
+
## 🔧 Development
|
254
|
+
|
255
|
+
### Setup Development Environment
|
256
|
+
|
257
|
+
```bash
|
258
|
+
git clone https://github.com/veridock/xsl.git
|
259
|
+
cd xsl
|
260
|
+
|
261
|
+
# Install Poetry
|
262
|
+
curl -sSL https://install.python-poetry.org | python3 -
|
263
|
+
|
264
|
+
# Install dependencies
|
265
|
+
poetry install --extras "full"
|
266
|
+
|
267
|
+
# Run tests
|
268
|
+
poetry run pytest
|
269
|
+
|
270
|
+
# Format code
|
271
|
+
poetry run black xsl/
|
272
|
+
poetry run isort xsl/
|
273
|
+
```
|
274
|
+
|
275
|
+
### Running Tests
|
276
|
+
|
277
|
+
```bash
|
278
|
+
# All tests
|
279
|
+
poetry run pytest
|
280
|
+
|
281
|
+
# With coverage
|
282
|
+
poetry run pytest --cov=xsl --cov-report=html
|
283
|
+
|
284
|
+
# Specific test categories
|
285
|
+
poetry run pytest -m "not slow" # Skip slow tests
|
286
|
+
poetry run pytest -m "integration" # Only integration tests
|
287
|
+
```
|
288
|
+
|
289
|
+
### Code Quality
|
290
|
+
|
291
|
+
```bash
|
292
|
+
# Format and lint
|
293
|
+
poetry run black xsl/ tests/
|
294
|
+
poetry run isort xsl/ tests/
|
295
|
+
poetry run flake8 xsl/ tests/
|
296
|
+
poetry run mypy xsl/
|
297
|
+
```
|
298
|
+
|
299
|
+
## 🤝 Contributing
|
300
|
+
|
301
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
302
|
+
|
303
|
+
### Quick Contribution Workflow
|
304
|
+
|
305
|
+
1. Fork the repository
|
306
|
+
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
307
|
+
3. Make your changes and add tests
|
308
|
+
4. Run tests: `poetry run pytest`
|
309
|
+
5. Format code: `poetry run black xsl/`
|
310
|
+
6. Commit: `git commit -m 'Add amazing feature'`
|
311
|
+
7. Push: `git push origin feature/amazing-feature`
|
312
|
+
8. Open a Pull Request
|
313
|
+
|
314
|
+
## 📋 Requirements
|
315
|
+
|
316
|
+
- **Python 3.8+**
|
317
|
+
- **Optional:** lxml, beautifulsoup4, requests (install with `[full]` extra)
|
318
|
+
|
319
|
+
## 📄 License
|
320
|
+
|
321
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
322
|
+
|
323
|
+
## 🙏 Acknowledgments
|
324
|
+
|
325
|
+
- Built with [lxml](https://lxml.de/) for robust XML processing
|
326
|
+
- Uses [Beautiful Soup](https://www.crummy.com/software/BeautifulSoup/) for HTML parsing
|
327
|
+
- Powered by [Poetry](https://python-poetry.org/) for dependency management
|
328
|
+
|
329
|
+
## 📞 Support
|
330
|
+
|
331
|
+
- 📖 **Documentation:** [GitHub Wiki](https://github.com/veridock/xsl/wiki)
|
332
|
+
- 🐛 **Bug Reports:** [GitHub Issues](https://github.com/veridock/xsl/issues)
|
333
|
+
- 💬 **Discussions:** [GitHub Discussions](https://github.com/veridock/xsl/discussions)
|
334
|
+
- 📧 **Email:** contact@veridock.com
|
335
|
+
|
336
|
+
---
|
337
|
+
|
338
|
+
**Made with ❤️ by the xsl team**
|