You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XSL循环后放置结束标签异常:仅服务器环境可复现

Troubleshooting Server-Only XSL 2.0 Issue

Got it, let’s break down why your XSL code works in online testers but fails on your server—this is almost always an environment-specific mismatch, not a syntax issue with your code (since online tools would catch that too). Here’s what to check step by step:

1. XSLT Processor Version Compatibility

Your code declares <xsl:stylesheet version="2.0"/>, but many server-side tools default to XSLT 1.0 (e.g., libxslt on Linux, Apache Xalan in Java). Online testers almost always use XSLT 2.0+ compliant processors like Saxon.

  • Check your server’s processor:
    • For Linux: Run xsltproc --version (if using libxslt, it will explicitly state it supports 1.0)
    • For Java apps: Verify if your app uses Saxon (supports 2.0+) or Xalan (default 1.0)
  • Fix: Switch to an XSLT 2.0-compatible processor on your server, or adjust your code to be 1.0-compliant if feasible.

2. Namespace Handling Discrepancies

Your code uses the xhtml namespace and exclude-result-prefixes="xhtml". Some servers have stricter namespace parsing rules:

  • Confirm your source XML’s elements are correctly bound to the xhtml namespace if required
  • Check if the server’s processor incorrectly retains the xhtml prefix in output (which could break rendering)
  • Test by temporarily removing exclude-result-prefixes to see if the issue resolves (this is a diagnostic step, not a permanent fix)

3. File Encoding/Line Ending Issues

Invisible formatting differences can trip up server processors:

  • Check encoding: On Linux, run file -i your.xsl to confirm it’s UTF-8 (match what you used in online tests)
  • Line endings: Windows-style CRLF line endings can cause parsing issues on Linux servers. Convert to LF with dos2unix your.xsl

4. Source XML Context Differences

Online tests use a sample XML, but your server’s actual XML might have subtle variations:

  • Double-check that the Contest element’s title attribute is exactly MAYOR (case-sensitive! Server XML might have Mayor or mayor)
  • Ensure the server’s XML doesn’t have extra nesting, namespaces, or missing elements that break the match="Contest" template

5. Server Output Pipeline Interference

Your server might modify the XSL output after conversion:

  • Test raw output: Run the conversion directly on the server via command line to verify correctness:
    # If using Saxon
    java -jar saxon-he-12.4.jar -s:your_input.xml -xsl:your.xsl -o:test_output.html
    # If using xsltproc (1.0 only)
    xsltproc your.xsl your_input.xml > test_output.html
    
  • Compare the raw output to what your server returns via browser/API—if they differ, check for server-side sanitization, compression, or Content-Type overrides.

If you can share the full Contest template, server error logs, or a snippet of the actual XML being processed on your server, we can narrow this down even further.

内容的提问来源于stack exchange,提问作者asandhu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:05:41