This is super straightforward stuff, it seems to me, but I cannot figure out how to select a node in the following format using XPath:
<w:p>
<w:pPr />
<w:customXml w:uri="DxDitaOXmlPub" w:element="msgnum">
<w:r>
<w:rPr>
<w:rStyle w:val="Dxmsgnum" />
</w:rPr>
<w:t>Consult your compliance officer.</w:t>
</w:r>
</w:customXml>
</w:p>
I have tried numerous variations on the following stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
<!-- Identity Transform -->
<xsl:template match="/ | @* | node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@* | node() "/>
</xsl:copy>
</xsl:template>
<xsl:template match="w:p[descendant::w:rPr/w:rStyle/@w:val='msgnum']">
<w:p>
<w:pPr>
<w:pStyle w:val="ActionRequired" />
</w:pPr>
<w:customXml w:uri="DxDitaOXmlPub" w:element="Dxmsgnum">
<w:r>
<w:rPr>
<w:rStyle w:val="Dxmsgnum" />
</w:rPr>
<w:t>
<xsl:value-of select="descendant::w:t"/>
</w:t>
</w:r>
</w:customXml>
</w:p>
</xsl:template>
</xsl:stylesheet>
The desired result is really nothing fancy, just modifying the w:pPr element to include a non-empty child w:pStyle:
<w:p>
<w:pPr>
<w:pStyle w:val="ActionRequired" />
</w:pPr>
<w:customXml w:uri="DxDitaOXmlPub" w:element="Dxmsgnum">
<w:r>
<w:rPr>
<w:rStyle w:val="Dxmsgnum" />
</w:rPr>
<w:t>
Consult your compliance officer.
</w:t>
</w:r>
</w:customXml>
</w:p>
I don’t see any reason why the stylesheet doesn’t do what I want as-is, but I am not termendously familiar with the OpenXML format, so maybe there’s something funky I’m not aware of?
EDIT: I have also tried matching on the @w:element as follows:
<xsl:template match="w:p[child::w:customXml/@w:element='msgnum']">
<w:p>
<w:pPr>
<w:pStyle w:val="ActionRequired" />
</w:pPr>
<w:customXml w:uri="DxDitaOXmlPub" w:element="msgnum">
<w:r>
<w:rPr>
<w:rStyle w:val="Dxmsgnum" />
</w:rPr>
<w:t>
<xsl:value-of select="descendant::w:t"/>OOGA BOOGA!
</w:t>
</w:r>
</w:customXml>
</w:p>
</xsl:template>
Try something like this instead? Copies over nodes normally, except inserts your desired child in empty w:pPr elements that are children of a w:p element.
Edit: Could you clarify what counts as an acceptable check? Any element containing an attribute equals to “msgnum”? I fixed the template match to reflect this case.