1

I have an xml :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ValidationErrors>
    <FieldName name="contact-detail-name">
        <Errors>
            <error>Please enter NAME</error>
        </Errors>
    </FieldName>
    <FieldName name="contact-detail-street-address">
        <Errors>
            <error>Please enter STREET ADDRESS</error>
        </Errors>
    </FieldName>
    <FieldName name="contact-detail-postcode">
        <Errors>
            <error>Number of digits exceeded. Please try again with 4 digits.</error>
        </Errors>
    </FieldName>
    <FieldName name="contact-detail-email-address">
        <Errors>
            <error>Please enter EMAIL</error>
        </Errors>
    </FieldName>
    <FieldName name="contact-detail-phone-number">
        <Errors>
            <error>Please enter PHONE NUMBER</error>
        </Errors>
    </FieldName>
</ValidationErrors>

I wrote an xsl to replace the node value of depending on the name attribute of :

 <xsl:template name="initialReplace" match="ValidationErrors/FieldName[@name='contact-detail-name']/Errors" >
        <error>Write a name</error>
</xsl:template>

and calling the above template. However i am getting the old value only.

1 Answer 1

1

You don't need a named template, simply write two templates

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="ValidationErrors/FieldName[@name='contact-detail-name']/Errors/error" >
  <error>Write a name</error>
</xsl:template>

That should do, unless the XML has namespaces you haven't shown.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.