0

This seems really simple but I've wasted a whole day trying to work this out:

Here is some simple xml

<Cube xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" 
xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" 
xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" 
xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200" 
xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200" 
xmlns:ddl300="http://schemas.microsoft.com/analysisservices/2011/engine/300" 
xmlns:ddl300_300="http://schemas.microsoft.com/analysisservices/2011/engine/300/300" 
xmlns:ddl400="http://schemas.microsoft.com/analysisservices/2012/engine/400" 
xmlns:ddl400_400="http://schemas.microsoft.com/analysisservices/2012/engine/400/400" 
xmlns:dwd="http://schemas.microsoft.com/DataWarehouse/Designer/1.0" 
dwd:design-time-name="56e2650a-1176-4739-be4f-e82aaaf501dd" 
xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
  <MdxScripts>
    <MdxScript dwd:design-time-name="c1bfa7b6-d041-4a75-918e-28822b676582">
      <Commands>
        <Command>
            <Text>
                    OLD
            </Text>
        </Command>
      </Commands>
    </MdxScript>
  </MdxScripts>
</Cube>

All I want to do is replace the value in the <Text /> node with a value I'm passing in.

However I can't even get the templates to find the node and replace it with a hard coded value.

<xsl:stylesheet
  version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2"
    xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2"
    xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100"
    xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200"
    xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200"
    xmlns:ddl300="http://schemas.microsoft.com/analysisservices/2011/engine/300"
    xmlns:ddl300_300="http://schemas.microsoft.com/analysisservices/2011/engine/300/300"
    xmlns:ddl400="http://schemas.microsoft.com/analysisservices/2012/engine/400"
    xmlns:ddl400_400="http://schemas.microsoft.com/analysisservices/2012/engine/400/400"
    xmlns:dwd="http://schemas.microsoft.com/DataWarehouse/Designer/1.0"
    dwd:design-time-name="56e2650a-1176-4739-be4f-e82aaaf501dd"
    xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"
>



    <xsl:param name="replacementScript">some passed in value</xsl:param>

    <xsl:output method="xml" encoding="utf-8" cdata-section-elements="value" indent="yes" />

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

    <xsl:template match="/Cube/MdxScripts/MdxScript/Commands/Command/Text">
            SOME HARD CODED VALUE
    </xsl:template>


</xsl:stylesheet>

Can anyone see what's wrong please? All I get at the moment is a copy of the output (except that namespace declarations are on the same line)

1
  • I've also had this problem before. Please see my solution below. Commented Feb 3, 2014 at 6:42

1 Answer 1

1

In your xsl, replace xmlns="http://schemas.microsoft.com/analysisservices/2003/engine" to xmlns:text="http://schemas.microsoft.com/analysisservices/2003/engine" and add exclude-result-prefixes="text"

Then replace the template with

<xsl:template match="/text:Cube/text:MdxScripts/text:MdxScript/text:Commands/text:Command/text:Text/text()">
    <xsl:value-of select="$replacementScript"/>
</xsl:template>
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. That's really great! Can you put in an explanation as to why the text: ns is needed please? BTW I've added /text() to the end of the match to only get the node value.
You can view some of the explanations here (stackoverflow.com/questions/1344158/…).
Would you please accept the answer if this has been helpful?
I will - I'm just giving it a few days to see if there are any others.

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.