With positional grouping in XSLT 2 or 3 you can solve it with
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="A">
<xsl:copy>
<xsl:for-each-group select="B" group-adjacent="(position() - 1) idiv 2">
<XYZ name="{@v}">
<MPN>{current-group()[2]/@v}</MPN>
</XYZ>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
With XSLT 1 you can process B[position() mod 2 = 1]
to create the XYZ
element and then navigate to following-sibling::B[1]
to create the MPN
element:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="A">
<xsl:copy>
<xsl:for-each select="B[position() mod 2 = 1]">
<XYZ name="{@v}">
<MPN>
<xsl:value-of select="following-sibling::B[1]/@v"/>
</MPN>
</XYZ>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>