Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
xslt node replace then ingest with javascript

I replace in memory XML node based on specific path before ingestion into NoSQL (marklogic) database.

Input: /doc1.xml

<image xmlns="http://coin/decimal">
      <DE>
         <denomination>1pf</denomination>
            <reverse>rye stalks</reverse>
            <obverse>oak sprig</obverse>
            <before>Anglo–Saxons</before>
      </DE>
      <GBP>
          <denomination>1p</denomination>
            <reverse>Arms</reverse>
            <obverse>Queen</obverse>
            <before>Anglo–Saxons</before>
      </GBP>
</image>

I replace the /before:image/before:DE/before:before value to a parameter value Xsl:

const beforeXsl =
 fn.head(xdmp.unquote(
`  <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:before="http://coin/decimal"  version="2.0">
 
    <xsl:template match="/Q{http://coin/decimal}image/Q{http://coin/decimal}DE/Q{http://coin/decimal}before">
            <xsl:element name="{local-name()}">
                <xsl:value-of select="$replace"/>
            </xsl:element>
    </xsl:template>
 
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
 
  </xsl:transform>
`));
 
xdmp.xsltEval(beforeXsl, doc, params)

Expected output:

<image xmlns="http://coin/decimal">
      <DE>
         <denomination>1pf</denomination>
            <reverse>rye stalks</reverse>
            <obverse>oak sprig</obverse>
            <before>Anglo-Dutch</before>
      </DE>
      <GBP>
          <denomination>1p</denomination>
            <reverse>Arms</reverse>
            <obverse>Queen</obverse>
            <before>Anglo–Saxons</before>
      </GBP>
</image>

I try to parameterize my xsl, but got the error:

[javascript] XSLT-BADPATTERN: MarkLogic extension syntax used, EQNames are not supported in XSLT mode
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Why! Shouldn’t it have been

var params = {};
params.nsProduct = "http://coin/decimal"
params.qPath = "/before:image/before:DE/before:before"
params.replaceValue="Anglo-Dutch"

const implReplace = fn.head(xdmp.unquote(
`
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:before="http://coin/decimal"  
    exclude-result-prefixes="#all" version="2.0">
    
    <xsl:param name="nsProduct"/>
    <xsl:param name="qPath"/>
    <xsl:param name="replaceValue" as="xs:anyAtomicType"/>
    
    <xsl:template match="node()[(xdmp:path(.) eq $qPath)]">
        <xsl:variable name="replace">
            <xsl:element name="{local-name()}" namespace="{$nsProduct}">
                <xsl:value-of select="$replaceValue"/>
            </xsl:element>
        </xsl:variable>
        <xsl:sequence select="$replace"/>
    </xsl:template>
    
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
    
</xsl:transform>

`));

xdmp.xsltEval(implReplace, doc, params)
about 4 years ago · Juan Pablo Isaza Denunciar

0

EQname are not supported in XSLT 2.0 stylesheets. You are attempting to use them in the @match expression.

Instead, use the before namespace-prefix that you already have defined in the XPath in your @match expression in your XSLT:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:before="http://coin/decimal"  version="2.0">

  <xsl:param name="replace"/>

  <xsl:template match="/before:image/before:DE/before:before">
        <xsl:element name="{local-name()}">
            <xsl:value-of select="$replace"/>
        </xsl:element>
  </xsl:template>

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

</xsl:transform>

You will also need to define an xsl:param or xsl:variable for the $replace, which is currently undefined.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda