I am transforming from xml to xml between two different formats.
My question:
How do i select the a sequence of subfields with the code 'B' that is a following sibling to 'A' but not the not to any other field.
If anyone can help me figure out how to "select" the correct nodes
Restrictions:
- XSLT 1.0
- I can't change the order of the content in datafields and due to the
amount of different posts. Different rulesets are applied based on previous and following subfields.
- I can't use specific positions(there no guarantee that 2 subfields
'B' will follow 'A' or similar)
Example:
Each post contains datafields with any number of subfields.
XML is similar to this
<datafield tag="1">
<subfield code="A"></subfield>
<subfield code="B"></subfield>
<subfield code="B"></subfield>
<subfield code="C"></subfield>
<subfield code="D"></subfield>
<subfield code="B"></subfield>
<subfield code="B"></subfield>
<subfield code="G"></subfield>
</datafield>
My xslt:
<xsl:template match="datafield[@tag=1]">
<xsl:choose>
<datafield>
<xsl:attribute name="tag">new tag</xsl:attribute>
<!-- Do not transfer subfield code='X' -->
<xsl:for-each select="./subfield[@code != 'X']">
<subfield>
<xsl:choose>
<xsl:when test="./@code = 'A'">
<xsl:attribute name="code">New code</xsl:attribute>
<!-- Find siblings with the code 'B'.PROBLEM all fields with the code B is selected-->
<xsl:when test="./following-sibling::subfield[@code='B']"> Apply operation here </xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
</subfield>
</xsl:if>
</xsl:for-each>
</datafield>
</xsl:when>
</xsl:choose>
I'm a pretty new stackoverflow user so if i missed any vital input please tell me and ill add it.