#!/bin/sh

WASM="./rs-xml2selected.wasm"

input(){
    echo '<?xml version="1.0"?><root>
        <page status="published">
          <title>The example xml</title>
        </page>
        <id>cafef00d-2026-0318-face-8624299792458</id>
        <timestamp>2026-03-18T23:59:59.012Z</timestamp>
        <version>2</version>
    </root>'
}

echo "--- Text (raw) ---"
input | wasmtime run "${WASM}" --xpath "/root/page/title/text()"

echo "--- Text (clean) ---"
input | wasmtime run "${WASM}" --xpath "string(/root/page/title)"

echo "--- Boolean ---"
input | wasmtime run "${WASM}" --xpath "count(/root/page) = 1"

echo "--- Number ---"
input | wasmtime run "${WASM}" --xpath "number(/root/version)"

echo "--- Attribute (raw) ---"
input | wasmtime run "${WASM}" --xpath "/root/page/@status"

echo "--- Attribute (clean) ---"
input | wasmtime run "${WASM}" --xpath "string(/root/page/@status)"

