0

I am trying to filter out a username for an incoming connection with .xsl file(DataPower appliance). I have 4 scenarios

user@domain.com - needs to stay the way it is.

user@remove.com - need to remove the domain part.

user@domain.com@remove.com - need to remove only the remove part.

user@remove.com.anything - again need to remove this and everything after.

There are 3 variables here. The 'user' can be anything. The domain can be anything. And the .anything after the remove.com, can be anything. @remove.com will ALWAYS be the same. Luckily that is the constant we can use.

Is there a simple if/then statement we can use to do this. We have tried many variations of If, when, contains, and can't seem to get it working. I can paste the code we are currently using if that will help.

Thanks.

4

2 回答 2

0

解决您的问题的一个好方法是正则表达式,尝试“regexp:match(yourExpressionGoesHere)”,然后您只需为每种情况编写特定的正则表达式。

于 2013-04-04T14:49:03.153 回答
0

我们想通了。对不起,我们已经在这几天了。

这是代码:

    <xsl:template match="@* | node()">
      <xsl:variable name="userid" select="substring-after(/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='Authenticate']/*[local-name()='username'],'@')"/>
<xsl:choose>
<xsl:when test="contains($userid,'remove')">     
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:*deleted*">
            <soapenv:Header />  
            <soapenv:Body>
                <urn:authenticate>
                    <userId0>
                           <xsl:value-of select="substring-before(/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='Authenticate']/*[local-name()='username'],'@remove.com')"/>
                    </userId0> 
                    <credential>
                           <xsl:value-of select="/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='Authenticate']/*[local-name()='password']"/>       
                    </credential>
                </urn:authenticate>
            </soapenv:Body>
        </soapenv:Envelope>
    </xsl:when>
    <xsl:otherwise>
       <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:*deleted*">
            <soapenv:Header />  
            <soapenv:Body>
                <urn:authenticate>
                    <userId0>
                           <xsl:value-of select="/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='Authenticate']/*[local-name()='username']"/>
                    </userId0> 
                    <credential>
                           <xsl:value-of select="/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='Authenticate']/*[local-name()='password']"/>       
                    </credential>
                </urn:authenticate>
            </soapenv:Body>
        </soapenv:Envelope>
</xsl:otherwise> 
</xsl:choose> 
    </xsl:template>
于 2013-04-05T12:54:29.987 回答