I am using the following function in php to load an xml doc into an xslt document, output xml, and replace document.xml in the word docx:
$xmlDocument = new DOMDocument();
$xmlDocument->load('xml/' . $xmlfile);
$xsltDocument = new DOMDocument();
$xsltDocument->load($xsltFile);
$xsltProcessor = new XSLTProcessor();
$xsltProcessor->importStylesheet($xsltDocument);
So I usually use this function in the XSLT file to pull an XML var:
<xsl:value-of select="PORT_REQUEST/WICIS/REMARKS" />
However, because XML vars are loaded directly into the XSLT document, I cannot use my friendly PHP reg exp’s, and I am struggling greatly trying to figure out how to make this work. I just need to pull the XML var (Telephone # in 1112223333 format) and put it in 111-222-3333 format.
This is what i have:
<xsl:analyze-string select="PORT_REQUEST/NUMBER_PORTABILITY/ADMINISTRATIVE/ATN"
regex="(^.{3})|(.{4}$)|((?<=(^.{3}))(.*?)(?=(.{4}$)))">
<xsl:matching-substring>
<xsl:number value="regex-group(1)" format="001"/>
<xsl:number value="regex-group(2)" format="001"/>
<xsl:number value="regex-group(3)" format="0001"/>
</xsl:matching-substring>
</xsl:analyze-string>
And it is not working, what I get instead of the re-formatted telephone number variable is an empty xml document, as whatever error I’m causing kills the entire thing.
Help
Are you sure you have access to XSLT2? By default PhP is likely to have XSLT1 unless you have hooked up saxon’s XSLT2 engine somewhere. In which case
xsl:analyze-stringandreplace()are not available, and you want something like