Jose Villanueva
Jose Villanueva

Reputation: 3

Using XPATH in xslt:value-of select to populate attritube

XML Data:

<ProcessData>
    <OUTPUT>
        <SourceAgent>Agent1</SourceAgent>
        <DestinationAgent>Agent2</DestinationAgent>
    </OUTPUT>
</ProcessData>

XSLT:

<sourceAgent QMgr="BSCMFT01" agent="'<xsl:value-of select="/ProcessData/OUTPUT/SourceAgent/text()"/>'"/>
<destinationAgent QMgr="BSCMFT01" agent="'<xsl:value-of select="/ProcessData/OUTPUT/DestinationAgent/text()"/>'"/>

Desired Output:

<sourceAgent QMgr="BSCMFT01" agent="Agent1"/>
<destinationAgent QMgr="BSCMFT01" agent="Agent2"/>

Error: The value of attribute "agent" associated with an element type "sourceAgent" must not contain the '<' character.

Summary:

Upvotes: 0

Views: 52

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116982

Use either the xsl:attribute instruction:

<sourceAgent QMgr="BSCMFT01">
    <xsl:attribute name="agent">
        <xsl:value-of select="/ProcessData/OUTPUT/SourceAgent"/>
    </xsl:attribute>
</sourceAgent>

or attribute value template:

<sourceAgent QMgr="BSCMFT01" agent="{/ProcessData/OUTPUT/SourceAgent}"/>

Upvotes: 1

Related Questions