xml - XSL to replace tags/elements and resave file? -
i don't have lot of experience in xsl functions.
i have variety of existing files, , have constant pile of new files, various 'flavours' of xml. nitf, etc.
what do, process xml files, , replace elements new element names, , resave them.
using oxygen app. files ingested dam.
i.e. in xml file, following code:
<abstract> <hl2>mercy animals doesn’t work on tips. investigators go hired, cameras.</hl2> </abstract>
i'd make code:
<title> <hl2>mercy animals doesn’t work on tips. investigators go hired, cameras.</hl2> </title>
so simple search , replace, of xml files, , resave them out, save file name, etc., , keep structure etc.
and can code have different transforms added it?
basically reason ingest various xml files various sources, xml format our dam requires. perhaps xsl-fo?
when have xslt problem amounts "keep things same tweak x, y , z" standard answer use "identity transformation". single template copy input document output unchanged, can selectively overridden other more specific templates make modifications. @ basic means
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <!-- identity template - copy verbatim except ... --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> </xsl:copy> </xsl:template> <!-- ... abstract elements, rename title --> <xsl:template match="abstract"> <title> <xsl:apply-templates select="@*|node()" /> </title> </xsl:template> </xsl:stylesheet>
but if input documents involve namespaces need adjust match expressions appropriately. e.g. if input document has xmlns="http://example.com"
unprefixed elements in document belong namespace , in order match them in xslt need create prefix binding , use in match
:
<xsl:stylesheet .... xmlns:ex="http://example.com"> <xsl:template match="ex:abstract">
as unprefixed names in match patterns , xpath expressions always mean nodes in no namespace.
Comments
Post a Comment