{
    "mode": "perldoc",
    "parameter": "XML::Grove::Subst",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/XML%3A%3AGrove%3A%3ASubst/json",
    "generated": "2026-07-05T09:30:26Z",
    "synopsis": "use XML::Grove::Subst;\n# Using subst method on XML::Grove::Document or XML::Grove::Element:\n$newgrove = $sourcegrove->subst( ARGS );\n$newgrove = $sourcegrove->substhash( ARG );\n# Using an XML::Grove::Subst instance:\n$subster = XML::Grove::Subst->new();\n$newgrove = $subster->subst( $sourcegrove, ARGS );\n$newgrove = $subster->substhash( $sourcegrove, ARG );",
    "sections": {
        "NAME": {
            "content": "XML::Grove::Subst - substitute values into a template\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use XML::Grove::Subst;\n\n# Using subst method on XML::Grove::Document or XML::Grove::Element:\n$newgrove = $sourcegrove->subst( ARGS );\n$newgrove = $sourcegrove->substhash( ARG );\n\n# Using an XML::Grove::Subst instance:\n$subster = XML::Grove::Subst->new();\n$newgrove = $subster->subst( $sourcegrove, ARGS );\n$newgrove = $subster->substhash( $sourcegrove, ARG );\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"XML::Grove::Subst\" implements XML templates. \"XML::Grove::Subst\" traverses through a source\ngrove replacing all elements with names `\"SUB:XXX\"' or `\"SUB:key\"' with their corresponding\nvalues from ARGS (a list) or ARG (a hash), repsectively.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "$groveobj->subst( *ARGS* ) =item $subster->subst( $groveobj, *ARGS* )\nSearch for `\"SUB:*XXX*\"' elements, where *XXX* is an array index, and replace the element\nwith the value from *ARGS*, a list of values. The return value is a new grove with the\nsubstitutions applied.\n\n$groveobj->substhash( *ARG* ) =item $subster->substhash( $groveobj, *ARG* )\nSearch for `\"SUB:key\"' elements and replace the element with the value from *ARG*, a hash of\nvalues. The hash key is taken from the `\"key\"' attribute of the `\"SUB:key\"' element, for\nexample, `\"<SUB:key key='foo'>\"'. The return value is a new grove with the substitutions\napplied.\n",
            "subsections": []
        },
        "EXAMPLE": {
            "content": "The following template, in a file `\"template.xml\"', could be used for a simple parts database\nconversion to HTML:\n\n<html>\n<head>\n<title><SUB:key key='Name'></title>\n</head>\n<body>\n<h1><SUB:key key='Name'></title>\n<p>Information for part number <SUB:key key='Number'>:</p>\n<SUB:key key='Description'>\n</body>\n</html>\n\nTo use this template you would first parse it and convert it to a grove, and then use\n`\"substhash()\"' every time you needed a new page:\n\nuse XML::Parser::PerlSAX;\nuse XML::Grove;\nuse XML::Grove::Builder;\nuse XML::Grove::Subst;\nuse XML::Grove::PerlSAX;\nuse XML::Handler::XMLWriter;\n\n# Load the template\n$b = XML::Grove::Builder->new();\n$p = XML::Parser::PerlSAX->new( Handler = $b );\n$sourcegrove = $p->parse( Source => { SystemId => 'template.xml' } );\n\n# Apply the substitutions\n$newgrove = $sourcegrove->substhash( { Name => 'Acme DCX-2000 Filter',\nNumber => 'N4728',\nDescription => 'The Best' } );\n\n# Write the new grove to standard output\n$w = XML::Handler::XMLWriter->new();\n$wp = XML::Grove::PerlSAX->new( Handler => $w );\n$wp->parse( Source => { Grove => $newgrove } );\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Ken MacLeod, ken@bitsko.slc.ut.us\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "",
            "subsections": [
                {
                    "name": "perl",
                    "content": "Extensible Markup Language (XML) <http://www.w3c.org/XML>\n"
                }
            ]
        }
    },
    "summary": "XML::Grove::Subst - substitute values into a template",
    "flags": [],
    "examples": [
        "The following template, in a file `\"template.xml\"', could be used for a simple parts database",
        "conversion to HTML:",
        "<html>",
        "<head>",
        "<title><SUB:key key='Name'></title>",
        "</head>",
        "<body>",
        "<h1><SUB:key key='Name'></title>",
        "<p>Information for part number <SUB:key key='Number'>:</p>",
        "<SUB:key key='Description'>",
        "</body>",
        "</html>",
        "To use this template you would first parse it and convert it to a grove, and then use",
        "`\"substhash()\"' every time you needed a new page:",
        "use XML::Parser::PerlSAX;",
        "use XML::Grove;",
        "use XML::Grove::Builder;",
        "use XML::Grove::Subst;",
        "use XML::Grove::PerlSAX;",
        "use XML::Handler::XMLWriter;",
        "# Load the template",
        "$b = XML::Grove::Builder->new();",
        "$p = XML::Parser::PerlSAX->new( Handler = $b );",
        "$sourcegrove = $p->parse( Source => { SystemId => 'template.xml' } );",
        "# Apply the substitutions",
        "$newgrove = $sourcegrove->substhash( { Name => 'Acme DCX-2000 Filter',",
        "Number => 'N4728',",
        "Description => 'The Best' } );",
        "# Write the new grove to standard output",
        "$w = XML::Handler::XMLWriter->new();",
        "$wp = XML::Grove::PerlSAX->new( Handler => $w );",
        "$wp->parse( Source => { Grove => $newgrove } );"
    ],
    "see_also": []
}