Reputation: 1
I have many files that contain coding similar to this:
<link linkaction="immediate" linktype="return" xlink:href="IETM://S50005#S50005-TOOL1"
xreftype="table">
<prompt>Multimeter</prompt>
</link>
That needs to be replaced with this:
<xref itemid="S50005-TOOL1" wpid="S50005"/>
Need to change the tagging structure, but keep the reference info. Is this possible with Notepad++?
Upvotes: 0
Views: 50
Reputation: 22157
Here is XSLT based solution. Notepad++ has XML Tools plugin for that.
To make input XML well-formed, I had to add a namespace to the root tag.
Input XML
<?xml version="1.0"?>
<root xmlns:xlink="URI">
<link linkaction="immediate" linktype="return"
xlink:href="IETM://S50005#S50005-TOOL1" xreftype="table">
<prompt>Multimeter</prompt>
</link>
<link linkaction="immediate" linktype="return"
xlink:href="IETM://S50005#S50018-TOOL15" xreftype="table">
<prompt>Multimeter</prompt>
</link>
</root>
XSLT
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="URI">
<xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="link">
<xref itemid="{substring-after(@xlink:href, '#')}" wpid="{substring-before(substring-after(@xlink:href, '#'),'-')}"/>
</xsl:template>
</xsl:stylesheet>
Output
<root xmlns:xlink="URI">
<xref itemid="S50005-TOOL1" wpid="S50005" />
<xref itemid="S50018-TOOL15" wpid="S50018" />
</root>
Upvotes: 1