xml - Xpath for Find & Replace? -
fellow forum members, i'm new xpath , have following question. let's example have 300 separate xml files , need make global text change may impact 40 of xml files. possible using xpath perform find & replace operation among 300 xml files? let's example words need globally change these words, "lbrt assembly" change "lbrs assembly". xpath offer ability perform such operation? know xpath @ querying xml elements. however, can perform find , replace operation? best application available 1 can use assist 1 in coding complex xpath query commands? opinion welcomed. in advance.
xpath cannot modify xml file. need xslt or xquery.
if global change (that is, if want change text regardless of context appears) inclined myself using text editor: goes against advice invariably give says when processing xml data should use xml tools. if finding text change depend on xml context, write little xslt 2.0 program it: it's dozen lines. core be:
(a) standard identity template copy elements unchanged
<xsl:template match="*"> <xsl:copy-of select="@*"/> <xsl:apply-templates select="node()"/> </xsl:template>
(b) drive processing:
<xsl:template name="main"> <xsl:apply-templates select="collection('my/dir/?select=*.xml')"/> </xsl:template>
(e) template create new output document each input document
<xsl:template match="/"> <xsl:result-document href="{replace(document-uri(.), '/dir/', '/outdir/')}"> <xsl:apply-templates/> </xsl:result-document> </xsl:template>
(d) template modify text nodes
<xsl:template match="text()"> <xsl:value-of select="replace(., 'xxx', 'yyy')"/> </xsl:template>
Comments
Post a Comment