在变量中插入一些东西

发布于 2024-11-03 08:45:08 字数 1711 浏览 1 评论 0原文

我将所有内容存储在变量中。当我收到此消息时,我需要将路径附加到我想要的令牌。 路径是路径=/;域名=.myorg.com ;

WasToken=AAECAzREQjgyNTY3NERCODI2Q0Zjbj1zYmswMi9vdT1iaG5zbS9vdT1pc2hzZy9vdT1kaXZhZG1pbi9vPWRvaANcWzW6mcn5IzHXtLr+BuYEMPTX; sessiontoken=DstTDbgX0ydK/nAixEvkBQCHrZ5CAar2DGq55U0Mo/6ll1+XEad3/cWyeXdO6hwmBePreLIW5d4CaoxiZHMEwuI5faG1j0UeRNizNJAw8JqEI0HuhpdpY5qSO46Iz+8WffmQoyemD/eQnWMkCeJb MwMHGIebSh7Q9mfC7wqoMqr+28IoeOYM93pPqVVwTiGOXEmiWdcp1S6WTKyw17E06S0GDLA8eZlFFxFksgGtQiqsmp2vevWvz2dpmYYUPZ6TK3+vsNjkV2urGj24DHIrFGgU5J2eJq9qNEdEatsu H71TJ6R0pyVK6h4FpaT1p5KurkdAZlIOl/Rpuzw2rnDNVJgW4PzWkeKIjoDDhlUhZ2cM4nNBoHqMGCz2HkwwbU72QVTzzXgwhOXtjrUlaaoZA==; WasToken=AAECAzREQjgyNTY3NERCODI2Q0Zjbj1zYmswMi9vdT1iaG5zbS9vdT1pc2hzZy9vdT1kaXZhZG1pbi9vPWRvaANcWzW6mcn5IzHXtLr+BuYEMPTX; NonceToken=61AF4E4A72A6749A8525787E0071880F; spinkerAcceptLanguages=en-us%2Cen%3Bq%3D0.5; spinkerStringLocale=zh; spinkerStyleLocale=en

在上面的事情中,我想将路径附加到 WasToken 的任何重复位置,因此在附加路径之后,它必须变成

tLr+BuYEMPTX;路径=/;域名=.myorg.com ; sessiontoken=DstTDbgX0ydK/nAixEvkBQCHrZ5CAar2DGq55U0Mo/6ll1+XEad3/cWyeXdO6hwmBePreLIW5d4CaoxiZHMEwuI5faG1j0UeRNizNJAw8JqEI0HuhpdpY5qSO46Iz+8WffmQoyemD/eQnWMkCeJb MwMHGIebSh7Q9mfC7wqoMqr+28IoeOYM93pPqVVwTiGOXEmiWdcp1S6WTKyw17E06S0GDLA8eZlFFxFksgGtQiqsmp2vevWvz2dpmYYUPZ6TK3+vsNjkV2urGj24DHIrFGgU5J2eJq9qNEdEatsu H71TJ6R0pyVK6h4FpaT1p5KurkdAZlIOl/Rpuzw2rnDNVJgW4PzWkeKIjoDDhlUhZ2cM4nNBoHqMGCz2HkwwbU72QVTzzXgwhOXtjrUlaaoZA==; WasToken=AAECAzREQjgyNTY3NERCODI2Q0Zjbj1zYmswMi9vdT1iaG5zbS9vdT1pc2hzZy9vdT1kaXZhZG1pbi9vPWRvaANcWzW6mcn5IzHXtLr+BuYEMPTX;路径=/;域名=.myorg.com ; NonceToken=61AF4E4A72A6749A8525787E0071880F; spinkerAcceptLanguages=en-us%2Cen%3Bq%3D0.5; spinkerStringLocale=zh; spinkerStyleLocale=en

如何使用 xsl 执行此操作。

I have the whole thing stored in variable. when I receive this, I need to append the path to token which token I wish.
path is path=/; domain=.myorg.com ;

WasToken=AAECAzREQjgyNTY3NERCODI2Q0Zjbj1zYmswMi9vdT1iaG5zbS9vdT1pc2hzZy9vdT1kaXZhZG1pbi9vPWRvaANcWzW6mcn5IzHXtLr+BuYEMPTX; sessiontoken=DstTDbgX0ydK/nAixEvkBQCHrZ5CAar2DGq55U0Mo/6ll1+XEad3/cWyeXdO6hwmBePreLIW5d4CaoxiZHMEwuI5faG1j0UeRNizNJAw8JqEI0HuhpdpY5qSO46Iz+8WffmQoyemD/eQnWMkCeJbMwMHGIebSh7Q9mfC7wqoMqr+28IoeOYM93pPqVVwTiGOXEmiWdcp1S6WTKyw17E06S0GDlLA8eZlFFxFksgGtQiqsmp2vevWvz2dpmYYUPZ6TK3+vsNjkV2urGj24DHIrFGgU5J2eJq9qNEdEAtsuH71TJ6R0pyVK6h4FpaT1p5KurkdAZlIOl/Rpuzw2rnDNVJgW4PzWkeKIjoDDhlUhZ2cM4nNBoHqMGCz2HkwwbU72QVTzzXgwhOXtjrUlaaoZA==; WasToken=AAECAzREQjgyNTY3NERCODI2Q0Zjbj1zYmswMi9vdT1iaG5zbS9vdT1pc2hzZy9vdT1kaXZhZG1pbi9vPWRvaANcWzW6mcn5IzHXtLr+BuYEMPTX; NonceToken=61AF4E4A72A6749A8525787E0071880F; spikerAcceptLanguages=en-us%2Cen%3Bq%3D0.5; spikerStringLocale=en; spikerStyleLocale=en

In the above thing I want to append path to WasToken wherever it is repeating so after appending path it must become

WasToken=AAECAzREQjgyNTY3NERCODI2Q0Zjbj1zYmswMi9vdT1iaG5zbS9vdT1pc2hzZy9vdT1kaXZhZG1pbi9vPWRvaANcWzW6mcn5IzHXtLr+BuYEMPTX; path=/; domain=.myorg.com ; sessiontoken=DstTDbgX0ydK/nAixEvkBQCHrZ5CAar2DGq55U0Mo/6ll1+XEad3/cWyeXdO6hwmBePreLIW5d4CaoxiZHMEwuI5faG1j0UeRNizNJAw8JqEI0HuhpdpY5qSO46Iz+8WffmQoyemD/eQnWMkCeJbMwMHGIebSh7Q9mfC7wqoMqr+28IoeOYM93pPqVVwTiGOXEmiWdcp1S6WTKyw17E06S0GDlLA8eZlFFxFksgGtQiqsmp2vevWvz2dpmYYUPZ6TK3+vsNjkV2urGj24DHIrFGgU5J2eJq9qNEdEAtsuH71TJ6R0pyVK6h4FpaT1p5KurkdAZlIOl/Rpuzw2rnDNVJgW4PzWkeKIjoDDhlUhZ2cM4nNBoHqMGCz2HkwwbU72QVTzzXgwhOXtjrUlaaoZA==; WasToken=AAECAzREQjgyNTY3NERCODI2Q0Zjbj1zYmswMi9vdT1iaG5zbS9vdT1pc2hzZy9vdT1kaXZhZG1pbi9vPWRvaANcWzW6mcn5IzHXtLr+BuYEMPTX; path=/; domain=.myorg.com ; NonceToken=61AF4E4A72A6749A8525787E0071880F; spikerAcceptLanguages=en-us%2Cen%3Bq%3D0.5; spikerStringLocale=en; spikerStyleLocale=en

How to do this using xsl.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城追梦 2024-11-10 08:45:08

XSLT 不太擅长递归和字符串操作,而这两者都需要,但这是可能的。这是我的解决方案(如果您可以确定某些字符串模式(例如,如果“WasToken”始终位于字符串的开头),则可能有比必要的更多的条件):

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="text" />

  <xsl:variable name="long.string">WasToken=AAECAzREQjgyNTY3NERCODI2Q0Zjbj1zYmswMi9vdT1iaG5zbS9vdT1pc2hzZy9vdT1kaXZhZG1pbi9vPWRvaANcWzW6mcn5IzHXtLr+BuYEMPTX; sessiontoken=DstTDbgX0ydK/nAixEvkBQCHrZ5CAar2DGq55U0Mo/6ll1+XEad3/cWyeXdO6hwmBePreLIW5d4CaoxiZHMEwuI5faG1j0UeRNizNJAw8JqEI0HuhpdpY5qSO46Iz+8WffmQoyemD/eQnWMkCeJbMwMHGIebSh7Q9mfC7wqoMqr+28IoeOYM93pPqVVwTiGOXEmiWdcp1S6WTKyw17E06S0GDlLA8eZlFFxFksgGtQiqsmp2vevWvz2dpmYYUPZ6TK3+vsNjkV2urGj24DHIrFGgU5J2eJq9qNEdEAtsuH71TJ6R0pyVK6h4FpaT1p5KurkdAZlIOl/Rpuzw2rnDNVJgW4PzWkeKIjoDDhlUhZ2cM4nNBoHqMGCz2HkwwbU72QVTzzXgwhOXtjrUlaaoZA==; WasToken=AAECAzREQjgyNTY3NERCODI2Q0Zjbj1zYmswMi9vdT1iaG5zbS9vdT1pc2hzZy9vdT1kaXZhZG1pbi9vPWRvaANcWzW6mcn5IzHXtLr+BuYEMPTX; NonceToken=61AF4E4A72A6749A8525787E0071880F; spikerAcceptLanguages=en-us%2Cen%3Bq%3D0.5; spikerStringLocale=en; spikerStyleLocale=en</xsl:variable>

  <xsl:template match="/">
    <!-- This template can be called from different places with different params fed into it for the beginning and ending delimiters and the string to be inserted. -->
    <xsl:call-template name="convert.string">
      <xsl:with-param name="string" select="$long.string" />
      <xsl:with-param name="delim.beg">WasToken=</xsl:with-param>
      <xsl:with-param name="delim.end">; </xsl:with-param>
      <xsl:with-param name="ins.string">path=/; domain=.myorg.com ; </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <!-- This is a template that will potentially be called later from itself (recursed) -->
  <xsl:template name="convert.string">
    <xsl:param name="string" />
    <xsl:param name="delim.beg" />
    <xsl:param name="delim.end" />
    <xsl:param name="ins.string" />
    <xsl:choose>
      <!-- Do a test using "starts-with" first (instead of just "contains") in case there's a situation where the ending delimiter text precedes the beginning delimiter text. -->
      <xsl:when test="starts-with($string, $delim.beg) and contains($string, $delim.end)">
        <!-- Output everything up until the first instance of the ending delimiter. -->
        <xsl:value-of select="substring($string, 1, string-length(substring-before($string,$delim.end)))" />
        <!-- Output the ending delimiter. -->
        <xsl:value-of select="$delim.end" />
        <!-- Ouput the string to be inserted. -->
        <xsl:value-of select="$ins.string" />
        <!-- Call this template again but only using the remainder text that follows the ending delimiter. -->
        <xsl:call-template name="convert.string">
          <xsl:with-param name="string" select="substring-after($string, $delim.end)" />
          <xsl:with-param name="delim.beg" select="$delim.beg" />
          <xsl:with-param name="delim.end" select="$delim.end" />
          <xsl:with-param name="ins.string" select="$ins.string" />
        </xsl:call-template>
      </xsl:when>
      <!-- This test catches text that contains (but doesn't start with) a set of delimiters (perhaps after $string was truncated in a previous pass).  It outputs everything in the string up until the first instance of the beginning delimiter. -->
      <xsl:when test="contains($string, $delim.beg) and contains(substring-after($string, $delim.beg), $delim.end)">
        <xsl:value-of select="substring-before($string, $delim.beg)" />
        <xsl:call-template name="convert.string">
          <xsl:with-param name="string" select="substring-after($string, $delim.end)" />
          <xsl:with-param name="delim.beg" select="$delim.beg" />
          <xsl:with-param name="delim.end" select="$delim.end" />
          <xsl:with-param name="ins.string" select="$ins.string" />
        </xsl:call-template>
      </xsl:when>
      <!-- Output the remainder text (or all of the text if the delimiters were never found). -->
      <xsl:otherwise>
        <xsl:value-of select="$string" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

XSLT is not very good at recursion and string manipulation, and this requires both, but it is possible. Here is my solution (which may have more conditions than necessary if you can be assured of certain string patterns (e.g. if "WasToken" is always at the beginning of the string)):

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="text" />

  <xsl:variable name="long.string">WasToken=AAECAzREQjgyNTY3NERCODI2Q0Zjbj1zYmswMi9vdT1iaG5zbS9vdT1pc2hzZy9vdT1kaXZhZG1pbi9vPWRvaANcWzW6mcn5IzHXtLr+BuYEMPTX; sessiontoken=DstTDbgX0ydK/nAixEvkBQCHrZ5CAar2DGq55U0Mo/6ll1+XEad3/cWyeXdO6hwmBePreLIW5d4CaoxiZHMEwuI5faG1j0UeRNizNJAw8JqEI0HuhpdpY5qSO46Iz+8WffmQoyemD/eQnWMkCeJbMwMHGIebSh7Q9mfC7wqoMqr+28IoeOYM93pPqVVwTiGOXEmiWdcp1S6WTKyw17E06S0GDlLA8eZlFFxFksgGtQiqsmp2vevWvz2dpmYYUPZ6TK3+vsNjkV2urGj24DHIrFGgU5J2eJq9qNEdEAtsuH71TJ6R0pyVK6h4FpaT1p5KurkdAZlIOl/Rpuzw2rnDNVJgW4PzWkeKIjoDDhlUhZ2cM4nNBoHqMGCz2HkwwbU72QVTzzXgwhOXtjrUlaaoZA==; WasToken=AAECAzREQjgyNTY3NERCODI2Q0Zjbj1zYmswMi9vdT1iaG5zbS9vdT1pc2hzZy9vdT1kaXZhZG1pbi9vPWRvaANcWzW6mcn5IzHXtLr+BuYEMPTX; NonceToken=61AF4E4A72A6749A8525787E0071880F; spikerAcceptLanguages=en-us%2Cen%3Bq%3D0.5; spikerStringLocale=en; spikerStyleLocale=en</xsl:variable>

  <xsl:template match="/">
    <!-- This template can be called from different places with different params fed into it for the beginning and ending delimiters and the string to be inserted. -->
    <xsl:call-template name="convert.string">
      <xsl:with-param name="string" select="$long.string" />
      <xsl:with-param name="delim.beg">WasToken=</xsl:with-param>
      <xsl:with-param name="delim.end">; </xsl:with-param>
      <xsl:with-param name="ins.string">path=/; domain=.myorg.com ; </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <!-- This is a template that will potentially be called later from itself (recursed) -->
  <xsl:template name="convert.string">
    <xsl:param name="string" />
    <xsl:param name="delim.beg" />
    <xsl:param name="delim.end" />
    <xsl:param name="ins.string" />
    <xsl:choose>
      <!-- Do a test using "starts-with" first (instead of just "contains") in case there's a situation where the ending delimiter text precedes the beginning delimiter text. -->
      <xsl:when test="starts-with($string, $delim.beg) and contains($string, $delim.end)">
        <!-- Output everything up until the first instance of the ending delimiter. -->
        <xsl:value-of select="substring($string, 1, string-length(substring-before($string,$delim.end)))" />
        <!-- Output the ending delimiter. -->
        <xsl:value-of select="$delim.end" />
        <!-- Ouput the string to be inserted. -->
        <xsl:value-of select="$ins.string" />
        <!-- Call this template again but only using the remainder text that follows the ending delimiter. -->
        <xsl:call-template name="convert.string">
          <xsl:with-param name="string" select="substring-after($string, $delim.end)" />
          <xsl:with-param name="delim.beg" select="$delim.beg" />
          <xsl:with-param name="delim.end" select="$delim.end" />
          <xsl:with-param name="ins.string" select="$ins.string" />
        </xsl:call-template>
      </xsl:when>
      <!-- This test catches text that contains (but doesn't start with) a set of delimiters (perhaps after $string was truncated in a previous pass).  It outputs everything in the string up until the first instance of the beginning delimiter. -->
      <xsl:when test="contains($string, $delim.beg) and contains(substring-after($string, $delim.beg), $delim.end)">
        <xsl:value-of select="substring-before($string, $delim.beg)" />
        <xsl:call-template name="convert.string">
          <xsl:with-param name="string" select="substring-after($string, $delim.end)" />
          <xsl:with-param name="delim.beg" select="$delim.beg" />
          <xsl:with-param name="delim.end" select="$delim.end" />
          <xsl:with-param name="ins.string" select="$ins.string" />
        </xsl:call-template>
      </xsl:when>
      <!-- Output the remainder text (or all of the text if the delimiters were never found). -->
      <xsl:otherwise>
        <xsl:value-of select="$string" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文